Results 1 to 5 of 5

Problem with import of txt file

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2021
    Posts
    351

    Problem with import of txt file

    I have got this code, but when I run it it does not work. The problem can be I use Fixed width, when I import the file
    Gives error on

              wrarr = Split(rearr(rec), delim)
    All I need is to import the file to where I need it.

    Sub ReadTxtFile()
    
    Dim ws As Worksheet
    Dim rearr(), wrarr()
    Dim fName As String
    Dim rowno As Long, colno As Long, rec As Long
    Dim cnt As Long, cnt2 As Long
    Dim delim As String
    
    Set ws = Worksheets("UnixO")
    fName = "C:\Do_It\test\UnixO Tapes.txt"
    
    delim = ","
    ifnum = FreeFile
    
    rowno = 1  'row 1
    colno = 1  'col A
    
        With ws
            Open fName For Input Access Read As #ifnum
                rec = 0
                    Do While Not EOF(ifnum)
                        Line Input #ifnum, tmpvar
                        rec = rec + 1
                        
                        ReDim Preserve rearr(1 To rec)
                        rearr(rec) = tmpvar
                        
                        wrarr = Split(rearr(rec), delim)
                        cnt2 = UBound(wrarr)
                            
                            For cnt = 0 To cnt2
                                ws.Cells(rowno, colno + cnt) = wrarr(cnt)
                            Next cnt
                         rowno = rowno + 1
                    Loop
                Close #ifnum
        End With
    End Sub
    I do have cross links for this.

    https://www.mrexcel.com/forum/excel-...ml#post4870883
    http://www.ozgrid.com/forum/showthre...goto=newpost**
    https://www.excelguru.ca/forums/show...rt-of-txt-file
    Last edited by hendrikbez; 07-19-2017 at 05:13 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with using VBA to import comma separated text file to worksheet - Excel 2013
    By tommagpieconsultants in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2015, 04:57 AM
  2. File import - select file and import sheet(1) from closed workbook
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2011, 03:15 AM
  3. import file from another sheet - location problem
    By j_r_m_c in forum Excel General
    Replies: 1
    Last Post: 02-19-2011, 03:38 PM
  4. import file problem
    By naaitie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2007, 04:42 PM
  5. Text Import Wizard: File Origin Problem
    By Baldbloke in forum Excel General
    Replies: 0
    Last Post: 03-29-2006, 09:55 AM
  6. [SOLVED] Import text file problem
    By condotta@shaw.ca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-15-2005, 12:45 PM
  7. problem import text file
    By Lynn in forum Excel General
    Replies: 1
    Last Post: 10-02-2005, 06:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1