Excel Macro - Clear cell contents of range of columns if criteria is met

stevia

New Member
Joined
May 30, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Is there a code which is able to look at each row of data in my spreadsheet, where column B in my spreadsheet has the specific text "Calendar". If this text matches, clear the cell contents in these rows in columns C to E while keeping the header intact.

This is a sample of what my spreadsheet looks like with dummy data.
1685499596666.png

and the end result I am looking for
1685499709026.png
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi @stevia
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.​

Try this:
VBA Code:
Sub Macro5()
  Dim lr As Long
  lr = Range("B" & Rows.Count).End(3).Row
  Range("A1:$E" & lr).AutoFilter 2, "Calendar"
  Range("C2:E" & lr).ClearContents
  Range("A1").AutoFilter
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Hi @stevia
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.​

Try this:
VBA Code:
Sub Macro5()
  Dim lr As Long
  lr = Range("B" & Rows.Count).End(3).Row
  Range("A1:$E" & lr).AutoFilter 2, "Calendar"
  Range("C2:E" & lr).ClearContents
  Range("A1").AutoFilter
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
The macro ran perfectly, thank you!!
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,651
Members
449,111
Latest member
ghennedy

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