How to clear specific cells

moheganburner

Board Regular
Joined
Dec 2, 2005
Messages
158
How can I just clear a specific range of cells? "ToSheet.Cells.ClearContents" is the only one I know and that clears the whole sheet. I have tried to modify it, but no luck.

Also, how can I add a line in my code that puts "Joe" in cell B4?

Thanks!
MB
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,022
<ul>[*]ToSheet.Range("B2:E7").ClearContents[*]Range("B4") = "Joe"[/list]Notes:
  1. This assumes that ToSheet is a worksheet object variable that has been set.
  2. The second example's syntax does not specify which worksheet, therefore it would put the value in cell B4 on the active worksheet.
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
Office Version
  1. 365
Platform
  1. Windows
answer to part 1:

Code:
Sub clear_stuff()
Sheets("sheet1").Range("A1:B2").ClearContents
End Sub

answer to part 2:

Code:
Sheets("sheet1").Range("B4").value="Joe"

Obviously substitute the correct sheet refs etc etc
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,021
Messages
5,834,992
Members
430,331
Latest member
Syed Yasir Hannan

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
Top