Question : How to delete a row based on the value of a cell? (macro)

Hi!

I want to create a macro that scans Column B of worksheet "TA1 GCSS Data"...
and, if it finds "North America"...  then delete that row.
So, overall, delete all rows where "North America" exists in Column B.

I can record a macro to figure out how to delete a row... but unsure on the searching column B part. Any ideas?

Thanks
Andrew

Answer : How to delete a row based on the value of a cell? (macro)

Try This:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Sub RemoveNA()

    Dim i As Long
    Dim tempCount As Long
    
    lastRow = Application.WorksheetFunction.CountA(Range("A:A"))
    
    For i = 2 To lastRow
        
        If Cells(i, 2).Value = "North America" Then
            Rows(i).Delete Shift:=xlUp
            i = i - 1
        Else
        End If
        
        tempCount = tempCount + 1 'Prevents endless loop
        If lastRow < tempCount Then
            Exit For
        Else
        End If
    Next

End Sub
Random Solutions  
 
programming4us programming4us