Jump to content
News Ticker
  • Welcome to the Community
  • Use the forum to troubleshoot your Excel & VBA Problems
  • We will be launching a new website soon! www.ExcelWTF.com/Learn ! Join us to learn VBA from the ground up!
Caleeco

[VBA Snippet] Importing Data From Textfile

Recommended Posts

Purpose

To import specific data from a .TXT file, line by line into an Excel Sheet. The text file here > GPS Data 

 

Code:

Sub ImportTextFile()
Dim myFile As String, textline As String
Dim i As Long
myFile = Application.GetOpenFilename()
i = 0
Open myFile For Input As #1
Do Until EOF(1)
    Line Input #1, textline
    
    If InStr(1, textline, "GPS Date/Time") Then
        Range("A1").Offset(i).Value = textline
        i = i + 1
    ElseIf InStr(1, textline, "GPS Position") Then
        Range("A1").Offset(i).Value = textline
        i = i + 1
    End If
Loop
Close #1

End Sub

 

Outcome

16ia5cm.jpg

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...