Delete certain range on a table if criteria is not met

Celticfc

Board Regular
Joined
Feb 28, 2016
Messages
153
I have a table named “employees” (A:AZ3000).

I would like VBA to clear contents of A:S of employees that are not “Manager” in Column C.

So if Colum C Row 7, is not “Manager” - Columns A7:S7 should clear contents and this should repeat up to row 3000.

I found some codes online but could not change them to my need. Many thanks in advance.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is one way:
Code:
Sub MyClearContents()

    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Loop through all rows from 2 to 3000
    For r = 2 To 3000
'       Check to see if "Manager" is not in column C
        If Cells(r, "C") <> "Manager" Then
'           Clear columns A:S
            Range(Cells(r, "A"), Cells(r, "S")).ClearContents
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,619
Members
452,661
Latest member
Nonhle

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