Clear Data Using Clear Contents

zach9208

Board Regular
Joined
Dec 15, 2015
Messages
117
I need help with this code. I just want the contents to be cleared until the last row. This code works perfectly when I have it set to delete, but not when I have it set to ClearContents.

Code:
Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).Delete Shift:=xlUp


Code:
Sub ClearDetailData()Sheet1.Activate
Application.ScreenUpdating = False
Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).ClearContents Shift:=xlUp
Application.ScreenUpdating = False

I need clear contents, because it is breaking formulas on cells referenced, since cells are being deleted.
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I need help with this code. I just want the contents to be cleared until the last row. This code works perfectly when I have it set to delete, but not when I have it set to ClearContents.

Code:
Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).Delete Shift:=xlUp


Code:
Sub ClearDetailData()Sheet1.Activate
Application.ScreenUpdating = False
Range(Range("A2"), ActiveCell.SpecialCells(xlLastCell)).ClearContents [B][COLOR="#FF0000"]Shift:=xlUp[/COLOR][/B]
Application.ScreenUpdating = False

I need clear contents, because it is breaking formulas on cells referenced, since cells are being deleted.
Remove the red highlighted text... the Delete method can take that argument but ClearContents cannot (nothing moves when you clear contents).
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,053
Members
449,206
Latest member
Healthydogs

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