+ Reply to Thread
Results 1 to 2 of 2

Importing Text File and Updating Excel Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    11-29-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Importing Text File and Updating Excel Worksheet

    I will try to be more clear of what is needed.

    I have a text file as database. It is a fixed width, content database.

    I need to import the file, segregate the fixed width datas into columns. And each line in the text file is a record and macro has to loop till the end of line in the text file.

    Anyone just please give heads up.

    Thank you.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Importing Text File and Updating Excel Worksheet

    Hi sebastianfrench

    Do you have a sample Text file?
    Some script from John Walkenback that may help?
    Sub ImportRange2()
        Set ImpRng = ActiveCell
        On Error Resume Next
        Open ThisWorkbook.Path & "\textfile.txt" For Input As #1
        If Err <> 0 Then
            MsgBox "Not found: " & ThisWorkbook.Path & "\textfile.txt", vbCritical, "ERROR"
            Exit Sub
        End If
        r = 0
        c = 0
        txt = ""
        Application.ScreenUpdating = False
        Do While Not EOF(1)
            Line Input #1, data
            For i = 1 To Len(data)
                char = Mid(data, i, 1)
                If char = "," Or i = Len(data) Then
                    ActiveCell.Offset(r, c) = txt
                    c = c + 1
                    txt = ""
                Else
                    If char <> Chr(34) Then _
                      txt = txt & Mid(data, i, 1)
                End If
            Next i
            c = 0
            r = r + 1
        Loop
        Close #1
        Application.ScreenUpdating = True
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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