Clear contents of a selected range

TheAaron

New Member
Joined
Oct 1, 2015
Messages
11
Hi :)

I'm having problems trying to clear the contents in a range I selected.
The code, say "w" is 10:

Range("A2").End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Resize(w, 8).Select
Range(Selection).ClearContents

I tried that code and it doesn't seem to work, any ideas?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Does this do it?

Howard

Code:
Sub myClear()
'Range("A2").End(xlDown).Select
' ActiveCell.Offset(1, 0).Select
' ActiveCell.Resize(w, 8).Select
' Range(Selection).ClearContents


Dim w As Long
w = 10
Range("A2").End(xlDown).Offset(1, 0).Resize(w, 8).ClearContents
End Sub
 
Upvote 0
Hi :)

I'm having problems trying to clear the contents in a range I selected.
The code, say "w" is 10:

Range("A2").End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Resize(w, 8).Select
Range(Selection).ClearContents

I tried that code and it doesn't seem to work, any ideas?
Assuming w=10, exactly what range of cells are you trying to clear with it (I want to know the real range on the worksheet that should be cleared)?
 
Upvote 0
As Howard has demonstrated, you don't need to actually select the range(s) here to perform these actions. In addition, selecting slows your code.

I would go with Howard's one line to do the ClearContents but for information, the problem with your code is the red part of this line.
Rich (BB code):
Range(Selection).ClearContents
Selection already is a Range, so all you needed was
Rich (BB code):
Selection.ClearContents
 
Upvote 0
I would go with Howard's one line to do the ClearContents...
I am probably wrong, but I have this nagging feeling that the OP does not really want to proceed downward from the activecell, but rather, upward (hence the question I asked).
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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