Option Explicit
Sub Suggestion()
Dim txtFilename As String, txtLine As String
Dim rptWS As Worksheet
Dim txtHandle As Long
Dim rptRow As Long
Dim txtLineSplit As Variant
Dim i As Long
Dim rptWave As Long, rptDate As Date
'get text file
txtFilename = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Select Txt File")
If txtFilename = "False" Then Exit Sub
'make new ws
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Report").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Worksheets.Add.Name = "Report"
Set rptWS = Worksheets("Report")
rptRow = 1
With rptWS
.Cells(rptRow, 1).Value = "Location"
'added Pallet
.Cells(rptRow, 2).Value = "Pallet"
.Cells(rptRow, 3).Value = "Item"
.Cells(rptRow, 4).Value = "Empl"
.Cells(rptRow, 5).Value = "Before"
.Cells(rptRow, 6).Value = "After"
.Cells(rptRow, 7).Value = "Wave"
.Cells(rptRow, 8).Value = "Date"
End With
rptRow = rptRow + 1
'open text file
txtHandle = FreeFile
Open txtFilename For Input As #txtHandle
'read each line
Do While Not EOF(txtHandle)
Line Input #txtHandle, txtLine
With Application.WorksheetFunction
txtLine = .Substitute(txtLine, Chr(34), "")
'non-printable characters NOT caught by CLEAN
txtLine = .Substitute(txtLine, Chr(160), Chr(32)) ' non-breaking space
txtLine = .Substitute(txtLine, Chr(127), Chr(7)) ' ASCII 7 = BEL char
txtLine = .Substitute(txtLine, Chr(129), Chr(7))
txtLine = .Substitute(txtLine, Chr(141), Chr(7))
txtLine = .Substitute(txtLine, Chr(143), Chr(7))
txtLine = .Substitute(txtLine, Chr(144), Chr(7))
txtLine = .Substitute(txtLine, Chr(157), Chr(7))
'remove leading, trailing, multiple spaces (inc. what was 160's)
txtLine = .Trim(txtLine)
'remove 0 - 31 (inc. what was 127, 129, 141, 143, 144, and 157)
txtLine = .Clean(txtLine)
txtLine = .Substitute(txtLine, ",", "")
txtLine = .Substitute(txtLine, ".00", "")
txtLine = .Substitute(txtLine, Chr(34), "")
End With
'Cycle Wave: 2767 Cycle Type: Wave Date Completed: 01/04/2023
'remember wave and date
If InStr(txtLine, "Cycle Wave:") > 0 Then
txtLineSplit = Split(txtLine, " ")
rptWave = CLng(txtLineSplit(2))
rptDate = CDate(txtLineSplit(8))
End If
If Len(txtLine) = 0 Then GoTo NextLine
If Left(txtLine, 1) = "-" Then GoTo NextLine
If Left(txtLine, 1) = "_" Then GoTo NextLine
If InStr(txtLine, "Column") > 0 Then GoTo NextLine
If InStr(txtLine, "Accuracy") > 0 Then GoTo NextLine
If InStr(txtLine, "Wave") > 0 Then GoTo NextLine
If InStr(txtLine, "From") > 0 Then GoTo NextLine
If InStr(txtLine, "Location") > 0 Then GoTo NextLine
If InStr(txtLine, "Wave") > 0 Then GoTo NextLine
If InStr(txtLine, "Server") > 0 Then GoTo NextLine
'New edge cases added
If InStr(txtLine, "Company") > 0 Then GoTo NextLine
If InStr(txtLine, "Warehouse") > 0 Then GoTo NextLine
If InStr(txtLine, "**") > 0 Then GoTo NextLine
If InStr(txtLine, "Funct") > 0 Then GoTo NextLine
If InStr(txtLine, "Ranges") > 0 Then GoTo NextLine
If InStr(txtLine, "Options") > 0 Then GoTo NextLine
If InStr(txtLine, "(D)ata") > 0 Then GoTo NextLine
If InStr(txtLine, "(D)aily") > 0 Then GoTo NextLine
If InStr(txtLine, "TWL") > 0 Then GoTo NextLine
txtLine = UCase(txtLine)
txtLineSplit = Split(txtLine, " ")
For i = LBound(txtLineSplit) To UBound(txtLineSplit) ' starts at 0
rptWS.Cells(rptRow, i + 1).Value = txtLineSplit(i)
Next I
rptWS.Cells(rptRow, 7).Value = rptWave
rptWS.Cells(rptRow, 8).Value = rptDate
rptRow = rptRow + 1
NextLine:
Loop
'close
Close #txtHandle
End Sub