BalloutMoe
Board Regular
- Joined
- Jun 4, 2021
- Messages
- 137
- Office Version
- 365
- Platform
- Windows
Hello all I have a code that reads through a text file,
I would like to reset the Do Loop after this condition is true If InStr(arrTxt(i), todaysdate) > 0, it runs perfect the first time but then it wont find anything on the next run. Any help how can I reset it the Do to the zero
Thank you
I would like to reset the Do Loop after this condition is true If InStr(arrTxt(i), todaysdate) > 0, it runs perfect the first time but then it wont find anything on the next run. Any help how can I reset it the Do to the zero
Thank you
VBA Code:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileopening = fso.OpenTextFile(txtFileName, 1)
arrTxt = Split(fileopening.ReadAll, vbCrLf)
For i = 0 To UBound(arrTxt)
If InStr(arrTxt(i), todaysdate) > 0 Then
i = i + 2
If InStr(arrTxt(i), "=MF") Then
'If InStr(arrTxt(i + j), "=MF") > 0 Then
i = i - 1
If InStr(arrTxt(i), "ReceiptNumber") > 0 Then
InvoiceArray = Split(arrTxt(i), "=")
InvoiceNumber = InvoiceArray(1)
lastR = ThisWorkbook.Worksheets("Sheet2").Range("B" & Sh.Rows.Count).End(xlUp).Row
ThisWorkbook.Worksheets("Sheet2").Range("B" & lastR + 1).Resize(1, 1).Value = InvoiceNumber
End If
i = i + 2
If InStr(arrTxt(i), "FirstName=") > 0 Then
CompanyArray = Split(arrTxt(i), "=")
CompanyName = CompanyArray(1)
lastR = ThisWorkbook.Worksheets("Sheet2").Range("C" & Sh.Rows.Count).End(xlUp).Row
ThisWorkbook.Worksheets("Sheet2").Range("C" & lastR + 1).Resize(1, 1).Value = CompanyName
End If
'I Need to reset it to 0 before finding the next If InStr(arrTxt(i), todaysdate) > 0 Then
Do While InStr(arrTxt(i + j), "[COMMENTS]") = 0
j = j + 1
'LiscPlate
If InStr(arrTxt(i + j), "FleetLicn=") > 0 Then
PlateArray = Split(arrTxt(i + j), "=")
LiscPlate = PlateArray(1)
lastR = ThisWorkbook.Worksheets("Sheet2").Range("E" & Sh.Rows.Count).End(xlUp).Row
ThisWorkbook.Worksheets("Sheet2").Range("E" & lastR + 1).Resize(1, 1).Value = Trim(LiscPlate)
End If
Loop
End If
End If 'If Instr
Next i