I have a column with a couple possible strings, and I want to know in which row they're.
Dim lx As Integer
Dim FoundExec As Range
With Worksheets("Load " & LoadNr(1)).Range("G10:G26")
Set FoundExec = .Find("Exec", LookIn:=xlValues)
If Not FoundExec Is Nothing Then
Dim FirstLoadAddress As String
FirstLoadAddress = FoundExec.Address
Do
lx = FoundExec.Row
Set FoundExec = .FindNext(FoundExec)
'Code...
Loop While FoundExec.Address <> FirstLoadAddress
End If
End With
This works for me as it's supposed to, but I want also to find the values "OVS", "OV" and "OS", as the same code is to follow after those inputs.
I treid
Dim lx As Integer
Dim FoundExec As Range
Dim FoundOVS As Range
Dim FoundOV As Range
Dim FoundOS As Range
Dim AllOSS As Range
With Worksheets("Load " & LoadNr(1)).Range("G10:G26")
Set FoundExec = .Find("Exec", LookIn:=xlValues)
Set FoundOVS = .Find("OVS", LookIn:=xlValues)
Set FoundOV = .Find("OV", LookIn:=xlValues)
Set FoundOS = .Find("OS", LookIn:=xlValues)
Set AllOSS = Application.Union(FoundExec, FoundOVS, FoundOV, FoundOS)
If Not AllOSS Is Nothing Then
Dim FirstLoadAddress As String
'Code...
FirstLoadAddress = AllOSS.Address
Do
lx = AllOSS .Row
Set AllOSS = .FindNext(AllOSS)
Loop While AllOSS.Address <> FirstLoadAddress
End If
End With
But that turns in ongoing loop.
Is there a way to do that quickly? and why turns the second in ongoing loop?
.Unionmultiple searches and then do a.FindNexton it. Check your code with aDebug.Print AllOSS.Addressjust after theDothen you'll understand whyDo Loopwill never exit.