abenitez77
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 149
When I use Find and FindNext, it is looping around the same 2 values it finds.
This is the code I use to search for "X" and when I use FindNext to keep searching, it finds the second "X". Then on the next FindNext it comes back to the first "X" I found. How do I make it stop at the last one that exists?
'Search for "X" markers **************************************************************************************
mySearch5 = "X"
Set iSheetE = Range("A44:O54").Find(What:=mySearch5, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not iSheetE Is Nothing Then
strBanner = iSheetE.Offset(0, 1).Value
strBannerCode = iSheetE.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
'Search Next X
Set iSheetE2 = .FindNext(iSheetE)
If Not iSheetE2 Is Nothing Then
strBanner2 = iSheetE2.Offset(0, 1).Value
strBannerCode2 = iSheetE2.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
'Search Next X
Set iSheetE3 = .FindNext(iSheetE2)
If Not iSheetE3 Is Nothing Then
strBanner3 = iSheetE3.Offset(0, 1).Value
strBannerCode3 = iSheetE3.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
Set iSheetE4 = FindNext(iSheetE3)
If Not iSheetE4 Is Nothing Then
strBanner4 = iSheetE4.Offset(0, 1).Value
strBannerCode4 = iSheetE.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
Set iSheetE5 = .FindNext(iSheetE4)
If Not iSheetE5 Is Nothing Then
strBanner5 = iSheetE5.Offset(0, 1).Value
strBannerCode5 = iSheetE5.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
....
This is the code I use to search for "X" and when I use FindNext to keep searching, it finds the second "X". Then on the next FindNext it comes back to the first "X" I found. How do I make it stop at the last one that exists?
'Search for "X" markers **************************************************************************************
mySearch5 = "X"
Set iSheetE = Range("A44:O54").Find(What:=mySearch5, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not iSheetE Is Nothing Then
strBanner = iSheetE.Offset(0, 1).Value
strBannerCode = iSheetE.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
'Search Next X
Set iSheetE2 = .FindNext(iSheetE)
If Not iSheetE2 Is Nothing Then
strBanner2 = iSheetE2.Offset(0, 1).Value
strBannerCode2 = iSheetE2.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
'Search Next X
Set iSheetE3 = .FindNext(iSheetE2)
If Not iSheetE3 Is Nothing Then
strBanner3 = iSheetE3.Offset(0, 1).Value
strBannerCode3 = iSheetE3.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
Set iSheetE4 = FindNext(iSheetE3)
If Not iSheetE4 Is Nothing Then
strBanner4 = iSheetE4.Offset(0, 1).Value
strBannerCode4 = iSheetE.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
Set iSheetE5 = .FindNext(iSheetE4)
If Not iSheetE5 Is Nothing Then
strBanner5 = iSheetE5.Offset(0, 1).Value
strBannerCode5 = iSheetE5.Offset(0, 2).Value
Else
GoTo NoMoreX
End If
....