Hi all,
Need your help to to add data to last row. (*Sorry for my bad English).
Im want extract data from text file to excel using VBA.
I got so different text file (based on date).
For the 1st time i manage to extract the data to the correct cell and column then when try to extract another data from another text file its been overwrite.
I need a code that can offset the next data below the first data.
Need your help to to add data to last row. (*Sorry for my bad English).
Im want extract data from text file to excel using VBA.
I got so different text file (based on date).
For the 1st time i manage to extract the data to the correct cell and column then when try to extract another data from another text file its been overwrite.
I need a code that can offset the next data below the first data.
VBA Code:
Private Sub CommandButton1_Click()
Dim myFile As String, text As String, textline As String
Dim sDate As Integer
Dim sID As Integer
Dim sT1 As Integer
Dim sT2 As Integer
Dim WS, WS1, WS2 As Worksheet
Set WS = Sheets("Main")
Set WS1 = Sheets("CtrThk")
Set WS2 = Sheets("TTV")
myFile = Sheets("Main").Range("B5")
'myFile = Application.GetOpenFilename()
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1
sDate = InStr(text, "Plant Order")
sID = InStr(text, "Inspector")
sT1 = InStr(text, "~P1")
sT2 = InStr(text, "~P2")
sT3 = InStr(text, "~P3")
WS1.Range("B11").Value = Mid(text, sDate + 36, 8)
WS1.Range("C11").Value = Mid(text, sID + 30, 5)
WS1.Range("D11").Value = Mid(text, sT1 + 30, 7)
WS1.Range("E11").Value = Mid(text, sT2 + 30, 7)
WS1.Range("F11").Value = Mid(text, sT3 + 30, 7)
WS2.Range("B11").Value = Mid(text, sDate + 36, 8)
WS2.Range("C11").Value = Mid(text, sID + 30, 5)
WS2.Range("D11").Value = Mid(text, sT1 + 44, 5)
WS2.Range("E11").Value = Mid(text, sT2 + 44, 5)
WS2.Range("F11").Value = Mid(text, sT3 + 44, 5)
End Sub