have I misunderstood Range.Clear?

Shakeable_Drip

Board Regular
Joined
May 30, 2023
Messages
50
Office Version
  1. 365
Platform
  1. Windows
I have a range called "clean" on my worksheet that I'd like to clear with VBA.
"clean" is a named range, A2:E1000&G2:G1000
I thought this was fairly simple, but I think I've misunderstood how something works. Debug doesn't like the Set CLEANS. I thought it was a conflict in name, I changed it to cleans and still no joy. Double checked for typo's
VBA Code:
Sub CLEAN_UP()
Dim SHT1 As Worksheet
Dim CLEANS As Range
Set SHT2 = Sheets("DATA INPUT")
Set CLEANS = Range("CLEAN")
CLEANS.Clear

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Where is this code, and exactly how is the CLEAN range defined? Workbook level, or worksheet-level?
 
Upvote 0
WorkSheet level,
Excel Formula:
='DATA INPUT'!$A$2:$E998&'DATA INPUT'!$G$2:$G$1000
Fixed the missing "$", still fails.
Excel Formula:
='DATA INPUT'!$A$2:$E$1000&'DATA INPUT'!$G$2:$G$1000
 
Upvote 0
That’s not a range, it’s an array created by concatenation of the values in those two ranges.
 
Upvote 0
Solution
Awwee face palm that makes sense, Thanks.
My skills are limited, but I can split "clean" into 2 parts "clean1" range A2:E1000 and "Clean2" range G2:G1000 and clear them separately.
Maybe there is a better way?
 
Upvote 0
Thanks again, its ugly, but works
VBA Code:
Sub CLEAN_UP()
Dim SHT1 As Worksheet
Dim CLEANS1 As Range, CLEANS2 As Range
Set SHT2 = Sheets("DATA INPUT")
Set CLEANS1 = Range("CLEAN1")
Set CLEANS2 = Range("CLEAN2")

CLEANS1.Clear
CLEANS2.Clear

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,021
Members
449,092
Latest member
ikke

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