Hi everyone, I am very new to Excel VBA and am trying to figure out how to import all the data in my txt file into excel to automate the process. As of right now, it is only importing the first three lines but I am unsure how I can alter it so it imports all the data. Here is the code I currently have as well as an image of the txt file I am trying to import (the data is tab delimited and each line contains a different number of tabs)
VBA Code:
Sub ImportText()
Dim fileToOpen As Variant
Dim fileFilterPattern As String
Dim wsMaster As Worksheet
Dim wbTextImport As Workbook
Application.ScreenUpdating = True
fileFilterPattern = "Text Files (*.txt; *.csv), *.txt; *.csv"
fileToOpen = Application.GetOpenFilename(fileFilterPattern)
If fileToOpen = False Then
' Input cancelled
MsgBox "No file selected."
Else
' we have a file to open
Workbooks.OpenText _
Filename:=fileToOpen, _
StartRow:=1, _
DataType:=xlDelimited, _
Tab:=True
Set wbTextImport = ActiveWorkbook
'Set wsMaster = ThisWorkbook.Worksheets.Add
Set wsMaster = ThisWorkbook.Worksheets("Data")
wbTextImport.Worksheets(1).Range("A1").CurrentRegion.Copy wsMaster.Range("A3")
wbTextImport.Close False
End If
Application.ScreenUpdating = True