Deleting Rows with a specific word

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
976
Office Version
  1. 2021
Platform
  1. Windows
HTML:
For Each sht In ActiveWorkbook.Worksheets
    If sht.Visible And (sht.Name = "Ramp") Then
        sht.Activate
    End If
    
    For r = Cells(Rows.Count, "M").End(xlUp).Row To 7 Step -1
        If Cells(r, "M").Value <> "Ramp" Then Rows(r).Delete
    Next r
End If

Hello All.
I'm trying to delete an entire row, if the word "Ramp" does not appear in column "M", beguinning on row 7...but I cant seem to get my End If and Next r in the proper place
Can someone lead me in the right direction please
Thank you
 
Try
Code:
Sht.Range("M" & r).Resize(, 5).Delete xlUp
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try
Code:
Sht.Range("M" & r).Resize(, 5).Delete xlUp


Code:
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible And UCase(sht.Name) = "RAMP" Then
    For r = sht.Cells(sht.Rows.Count, "M").End(xlUp).Row To 7 Step -1
        If UCase(sht.Cells(r, "M").Value) <> "RAMP" Then
        sht.Range("M" & r).Resize(, 5).Delete xlUp
    Next r
End If
Next sht

So I'm just not following why Im getting a compile error "Next with out a For" in the above code, what am i doing Wrong?
Thanks
 
Upvote 0
You're missing an "End If" before the "Next r"
 
Upvote 0

Forum statistics

Threads
1,216,031
Messages
6,128,424
Members
449,450
Latest member
gunars

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top