Would like to Clear contents of last row if...

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
The code below clears entire row contents if the word 'Unused' is found in column C. I'd like to restrict this to only the last row for each loop. ie: if 'Unused' is found in cell C13, 'Cars' is in cell C14 and 'Unused' is in C15 & C16, then clear row 15 & 16 but don't clear row 13, or anything 14 or above.

How can I do this?

Thanks
jim

Code:
Sub DeleteUnused()

    Last = Range("C55").End(xlUp).Row
    For i = Last To 8 Step -1
        If (Cells(i, "C").Value) = "Unused" Then
            Cells(i, "A").EntireRow.ClearContents
        End If
    Next i
    

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi auto.pilot,

Try:

Code:
Sub DeleteUnused()
 
    Last = Range("C55").End(xlUp).Row
    For i = Last To 8 Step -1
        If (Cells(i, "C").Value) <> "Unused" Then Goto x
        If (Cells(i, "C").Value) = "Unused" Then
            Cells(i, "A").EntireRow.ClearContents
        End If
    Next i
 
x:
End Sub
 
Upvote 0
Hi
Try :

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = LR To 8 Step -1
If Range("c" & i).Value <> "Unused" Then Exit Sub
If Range("C" & i).Value = "Unused" Then Rows(i).ClearContents
Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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