ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Loop (https://www.excelbanter.com/excel-discussion-misc-queries/117620-loop.html)

Heather O'Malley

Loop
 
Trying to Loop the below macro until foundcell is nothing, any ideas?

Range("A1").Select

Dim FoundCell As Range
With Worksheets("StockSheet")

Range("A1").Select

Set FoundCell = .Cells.Find(What:="BOO", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If FoundCell Is Nothing Then

Else

FoundCell.EntireRow.Delete
End If

End With

Bob Phillips

Loop
 
Sub yty()
Dim FoundCell As Range
Dim rng As Range
Dim sFirst As String

Range("A1").Select

With Worksheets("StockSheet")

Set FoundCell = .Cells.Find(What:="BOO", After:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False)

If Not FoundCell Is Nothing Then
sFirst = FoundCell.Address
Set rng = FoundCell

Do
Set FoundCell = .FindNext(FoundCell)
If Not FoundCell Is Nothing Then
Set rng = Union(rng, FoundCell)
End If
Loop While Not FoundCell Is Nothing And FoundCell.Address <
sFirst

End If

If Not rng Is Nothing Then rng.EntireRow.Delete

End With

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Heather O'Malley" wrote in message
. ..
Trying to Loop the below macro until foundcell is nothing, any ideas?

Range("A1").Select

Dim FoundCell As Range
With Worksheets("StockSheet")

Range("A1").Select

Set FoundCell = .Cells.Find(What:="BOO", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If FoundCell Is Nothing Then

Else

FoundCell.EntireRow.Delete
End If

End With





All times are GMT +1. The time now is 04:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com