Clear a range of cells better than this?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
273
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a sheet with a button on it "clear template". If the user presses it, a macro is triggered that clears the contents of about forty cells. At the moment I have a raft of
VBA Code:
    Range("D6").Select
    Selection.ClearContents
    
    Range("D8").Select
    Selection.ClearContents
    
    Range("D10").Select
    Selection.ClearContents

etc. Is there a way I can put all the cells into a range and then just clear contents that way?

Many thanks!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
How about
VBA Code:
Sub TheWennerWoman()
   Range("D6, D8, D10").ClearContents
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

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