Range.Clear fails when range empty

always_confused

Board Regular
Joined
Feb 19, 2021
Messages
68
Office Version
  1. 2016
Platform
  1. Windows
Hello. I am making a macro that fills in par of a range. However, the size of the total filled range is variable. I would like to start by clearing a large range before filling a smaller section. However, on the first iteration, the range is totally empty, and I get an error. Is it possible to use Range.Clear on an empty range or do I need to figure out some other way of making sure it's empty? This needs to happen at the beginning of one iteration, not the end of the previous one.

Lets say the larger range is Range("A:A") and I want to use Range("A1:A30"), then the next time Range("A1:A20"). I would like to just start my macro with Range("A:A").Clear, so that regardless of the used rows, they're all gone when I run the macro.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can use Range.Clear on empty cells not a problem.
 
Upvote 0
Solution
What error do you get & what is your code?
 
Upvote 0
What error do you get & what is your code?
I just got rid of it and it's working fine now. I replaced it with
VBA Code:
Sheets("name").Cells.ClearContents
and that works fine. Can't remember what the error was, it's kind of a crazy project so I might just be missing something in one of my Subs but who's to say now
 
Upvote 0
Glad its sorted & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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