Help with named range

OverhandLeft

New Member
Joined
Sep 1, 2008
Messages
9
Hello,

I have a macro that results in an ouput file of an excel spreadsheet.

There is a named range in the macro the clears data in the assigned range.

Let's say the range name is CLEAR_DATA with the range being
='Sheet2'!EG$78:EG$85,'Sheet2'!EG$92:EG$94

For some reason, when I run the macro to get the output file,
data is cleared from A78:A85 and A92:A94

Then I check the output file's range for CLEAR_DATA and I get
='Sheet2'!A$78:A$85,'Sheet2'!A$92:A$94

Would anyone happen to know what would cause this or how to
fix it?

As always, Thanks in advance to anyone that could help.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Post your macro code, without seeing it people will have to guess the problem.
 
Upvote 0
Hi

='Sheet2'!EG$78:EG$85,'Sheet2'!EG$92:EG$94

is a relative range. The columns can vary, depending on what cell is active. If you don't want it to change make it absolute:

='Sheet2'!$EG$78:$EG$85,'Sheet2'!$EG$92:$EG$94
 
Upvote 0
PGC,

I tried absolute and I get a "range of object global failed.

It is not really critical that I clear that area of the spreadsheet

so I think I will just leave it be, without clearing it. Thanks anyway
 
Upvote 0
Well, if you don't need it you may skip it.

Anyway, I just tried it and had no problem

Code:
Sub Test()
 
' define the name
Names.Add "CLEAR_DATA", "='Sheet2'!$EG$78:$EG$85,'Sheet2'!$EG$92:$EG$94"

 
' populate the range
Range("CLEAR_DATA").Value = "X"
 
' clear the range
Range("CLEAR_DATA").Clear
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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