Clear a range of cells better than this?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
284
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,468
Messages
6,130,800
Members
449,595
Latest member
jhester2010

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