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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
<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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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