Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Find_Example_WithLoop()
- Dim CL As Range, FirstFoundAddress As String
- Dim WS As Worksheet: Set WS = ActiveSheet
- 'FIND SYNTAX By PGCodeRider
- 'LOOKIN: xlFormulas , xlValues , or xlNotes
- 'LookAT: xlWhole or XlPart
- 'SearchOrder: xlByRows or xlByColumns
- 'SearchDirection: xlNext or xlPrevious
- 'MatchCase: True or False
- 'FindNext - Continues a search that was begun with the Find method. Finds the next cell that matches those same conditions.
- ' Find first instance on sheet
- Set CL = WS.Cells.Find(What:="BOOOOM", _
- After:=WS.Cells(1, 1), _
- LookIn:=xlFormulas, _
- LookAt:=xlPart, _
- SearchOrder:=xlByRows, _
- SearchDirection:=xlNext, _
- MatchCase:=False, _
- SearchFormat:=False)
- If Not CL Is Nothing Then
- ' if found, remember location, else ends if-statement
- FirstFoundAddress = CL.Address
- Do
- 'DO SOMETHING!!
- ' find next instance
- Set CL = WS.Cells.FindNext(After:=CL)
- ' repeat until finds original cell
- Loop Until FirstFoundAddress = CL.Address
- End If
- Next
- End Sub
Add Comment
Please, Sign In to add comment