ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using a named range in a header with VBA? (https://www.excelbanter.com/excel-discussion-misc-queries/52351-using-named-range-header-vba.html)

[email protected]

Using a named range in a header with VBA?
 
I'd like to apply a named range to headers in a file. I did a search
and found some syntax that is close, but still generating an error.
The named range is "DollarVal". The code I have is

ActiveSheet.PageSetup.RightHeader = "Total: " & Range(DollarVal)

Any thoughts? Thanks!


Bob Phillips

Using a named range in a header with VBA?
 
You need to enclose the name in quotes.

But if you want a total, shouldn't you sum it as well?

ActiveSheet.PageSetup.RightHeader = "Total: " &
Application.SUM(Range("DollarVal"))


--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
ups.com...
I'd like to apply a named range to headers in a file. I did a search
and found some syntax that is close, but still generating an error.
The named range is "DollarVal". The code I have is

ActiveSheet.PageSetup.RightHeader = "Total: " & Range(DollarVal)

Any thoughts? Thanks!




[email protected]

Using a named range in a header with VBA?
 
Bob- Thanks for such a quick response. I still get an error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

Am I missing something?


Bob Phillips

Using a named range in a header with VBA?
 
Is it NG wrap-around?

Try

ActiveSheet.PageSetup.RightHeader = "Total: " & _
Application.SUM(Range("DollarVal"))


--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
ups.com...
Bob- Thanks for such a quick response. I still get an error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

Am I missing something?




[email protected]

Using a named range in a header with VBA?
 
It's not a word-wrap issue; I have it all on one line.

As a test I closed Excel and re-started; I created the named range and
started a new macro with only one line (the one you posted). That
generated the same error when I ran it.

I looked at the MS Knowledge Base and found an article
http://support.microsoft.com/default...b;en-us;319832
that talks about unqualified references in VB (not VBA). Could this be
a similar situation?


Bob Phillips

Using a named range in a header with VBA?
 
It doesn't look related to me. A long-shot, but check if you have any
missing references (ToolsReferences), uncheck them if so.

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
ups.com...
It's not a word-wrap issue; I have it all on one line.

As a test I closed Excel and re-started; I created the named range and
started a new macro with only one line (the one you posted). That
generated the same error when I ran it.

I looked at the MS Knowledge Base and found an article
http://support.microsoft.com/default...b;en-us;319832
that talks about unqualified references in VB (not VBA). Could this be
a similar situation?





All times are GMT +1. The time now is 01:37 AM.

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