ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   What causes runtime error 1004? (https://www.excelbanter.com/excel-discussion-misc-queries/52524-what-causes-runtime-error-1004-a.html)

[email protected]

What causes runtime error 1004?
 
I have a macro that consists of these 3 lines:
Sub Macro2()
ActiveSheet.PageSetup.RightHeader = Range("TestNamedRange")
End Sub

It's meant to include the value of a textual named range in a header.
This macro generates
Runtime error 1004
Method 'range' of object '_global' failed

What causes this error? I have tried different variations of
declarations, searching this forum, and traded posts with Bob Phillips
(no aspersions intended-I think the thread just faded) to no avail.
Any ideas?


Jim Rech

What causes runtime error 1004?
 
Open the Define Name dialog (Ctrl-F3 is the shortcut) and make sure the name
TestNamedRange appears and that it refers to a cell.

--
Jim
wrote in message
oups.com...
|I have a macro that consists of these 3 lines:
| Sub Macro2()
| ActiveSheet.PageSetup.RightHeader = Range("TestNamedRange")
| End Sub
|
| It's meant to include the value of a textual named range in a header.
| This macro generates
| Runtime error 1004
| Method 'range' of object '_global' failed
|
| What causes this error? I have tried different variations of
| declarations, searching this forum, and traded posts with Bob Phillips
| (no aspersions intended-I think the thread just faded) to no avail.
| Any ideas?
|



[email protected]

What causes runtime error 1004?
 
Jim-
The named range had been set up as a variable, with a value applied to
the named rather than referring to a range. When I changed it to refer
to a range, the code worked: thanks!

What is the syntax to apply the named range that has a forced value
attached?

Thanks for your help!


Jim Rech

What causes runtime error 1004?
 
If you've created a name that refers to a string you can do this:

ActiveSheet.PageSetup.RightHeader = Evaluate(Names("HeaderString").Value)

The Evaluate is to peal off the "=" and quotes you see around the definition
of the name in the Define Name dialog.

--
Jim
wrote in message
oups.com...
| Jim-
| The named range had been set up as a variable, with a value applied to
| the named rather than referring to a range. When I changed it to refer
| to a range, the code worked: thanks!
|
| What is the syntax to apply the named range that has a forced value
| attached?
|
| Thanks for your help!
|



[email protected]

What causes runtime error 1004?
 
That did it- thanks again!



All times are GMT +1. The time now is 07:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com