I am doing an exercise where I am searching countless data entries in a bad format and finding what I need. Below is very sample data. I can find the midway point all the time fine. But it is getting the data between MidwayPoint and NewStart.
I tried IF statements but keep getting locked up, and the fact that the data here isn't always stacked neatly. Sometimes spaces jump in like you see below.
How Can I best loop to always capture all the data between MP and NS?
[TABLE="width: 93"]
<tbody>[TR]
[TD]Start[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Midway Point[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]NewStart[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 93"]
<tbody>[TR]
[TD]
[/TD]
[/TR]
</tbody>[/TABLE]
I tried IF statements but keep getting locked up, and the fact that the data here isn't always stacked neatly. Sometimes spaces jump in like you see below.
How Can I best loop to always capture all the data between MP and NS?
[TABLE="width: 93"]
<tbody>[TR]
[TD]Start[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Midway Point[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]NewStart[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
[TR]
[TD]data[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 93"]
<tbody>[TR]
[TD]
Code:
indi = 1
For i = 1 To lastrow
If (InStr(1, inarr(i, 1), "Invoice # S", vbTextCompare)) > 0 Then
If (InStr(1, inarr(i + 7, 1), "Shipping Instr :", vbTextCompare)) > 0 Then
If WorksheetFunction.CountA(inarr(i + 8, 1)) > 0 Then
Num8 = inarr(i + 8, 1)
ElseIf WorksheetFunction.CountA(inarr(i + 8, 1)) = 0 Then
Num8 = ""
End If
If (InStr(1, inarr(i + 7, 1), "Shipping Instr :", vbTextCompare)) = 0 Then
Num8 = ""
End If
Num7 = Trim(Split(inarr(i + 7, 1), "Shipping Instr :")(1))
Else: Num7 = ""
End If
outarr(indi, 6) = Num7 & Num8
indi = indi + 1
End If
Next i
[/TR]
</tbody>[/TABLE]
Last edited: