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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,761
Office Version
  1. 365
Platform
  1. Windows
Post your macro code, without seeing it people will have to guess the problem.
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
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
 

OverhandLeft

New Member
Joined
Sep 1, 2008
Messages
9
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
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,286
Messages
5,836,425
Members
430,428
Latest member
Deepak Tanwar

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
Top