djh wrote...
How would this be done in VBA?
Sub s4st()
Const END_OF_FIRST As String = "foo"
Const START_OF_LAST As String = "bar"
Dim c As Range
Static fmc As String
On Error GoTo CleanUp
If ActiveCell.Address(0, 0) = "A1" Then
Set c = ActiveSheet.UsedRange.Cells( _
ActiveSheet.UsedRange.Cells.Count _
)
Else
Set c = ActiveCell
End If
Set c = ActiveSheet.UsedRange.Find( _
What:=END_OF_FIRST, _
After:=c, _
SearchDirection:=xlNext, _
LookIn:=xlValues, _
LookAt:=xlPart _
)
If fmc = "" Then fmc = c.Address(0, 0)
Do
If c.Value Like "*" & END_OF_FIRST _
And c.Offset(0, 1).Value Like START_OF_LAST & "*" Then
c.Activate
Exit Sub
End If
Set c = ActiveSheet.UsedRange.Find( _
What:=END_OF_FIRST, _
After:=c, _
SearchDirection:=xlNext, _
LookIn:=xlValues, _
LookAt:=xlPart _
)
Loop While c.Address(0, 0) <> fmc
CleanUp:
If c Is Nothing Then
MsgBox _
Prompt:="No cells found containing" & Chr(13) & END_OF_FIRST, _
Title:="Search For Split Text"
ElseIf c.Address(0, 0) = fmc Then
MsgBox _
Prompt:="No more matching cells found", _
Title:="Search For Split Text"
End If
End Sub
The text is split across the cells, because the spreadsheets are
the result of report text files with columns of data being
imported.
...
You could import without parsing, so all lines of text in a singl
column. Then you could search for the unbroken text, delete the line
containing it (or whatever else you do), and finally parse th
remaining lines into fields in multiple columns.
Purge before parsing rather than parse before purging