Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all
I have the following code. The theory is that the code loops through a range supplied by name, and looks for matches in a set of data. The code almost works! But not quite. Many rows are removed, but some remain. However, running the procedure a second time results in all the remaining matches being removed. Anyone any ideas? Incidentally, I've been testing it on an export of the Orders table from Northwind, with a second sheet holding 3 or 4 countries for which I want to remove data. Thanks very much, Andrew Sub RemoveSpecifiedRows() Dim strCriteriaRange As String, strCol As String Dim rngCriteria As Range Dim rngCell1 As Range Dim rngCell2 As Range Dim intCounter As Integer strCriteriaRange = InputBox("Enter name of range containing the criteria values") strCol = InputBox("Enter the column letter to search") Set rngCriteria = Range(strCriteriaRange) Application.ScreenUpdating = False For Each rngCell1 In rngCriteria.Cells For Each rngCell2 In ActiveSheet.Columns(strCol).Cells If rngCell2.Value = rngCell1.Value Then rngCell2.EntireRow.Delete shift:=xlShiftUp intCounter = intCounter + 1 End If Next rngCell2 Next rngCell1 Application.ScreenUpdating = True MsgBox intCounter & " rows were successfully deleted" End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
loop does not work correctly | Excel Programming | |||
Why this basic LOOP does not work! | Excel Programming | |||
For Each - loop doesn't work. | Excel Programming | |||
Would a loop work? | Excel Programming | |||
Why doesn't my loop work? | Excel Programming |