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
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
<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,760
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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,522
Messages
5,572,633
Members
412,475
Latest member
JaredNAU
Top