using VBA to clear cell contents

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello,

I feel like this is a dumb question, since I should know how to do this and can't remember. I need to clear the contents of multiple cells in the current sheet. I keep trying
Code:
Cells("D8:G8").Clearcontents
and that is clearly not it.
Any help in the correct direction would be greatly appreciated!

- Andrew
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about

Code:
Range("D8:G8").Select
Selection.ClearContents
 
Upvote 0
How about

Code:
Range("D8:G8").Select
Selection.ClearContents
Very rarely do you have to select something in Excel in order to do something with it. Your suggested code can be written compactly like this...
Code:
Range("D8:G8").ClearContents
Think about it... you are clearing the contents of the Selection, but what is the selection? It is what you selected... Range("D8:G8"), so you might as well just clear what you selected directly and cut out the middle step.
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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