Hidden characters

R

Rookie 1st class

Two formulas appear the same:
ActiveSheet.PageSetup.RightHeader = _
"&""Arial Narrow,Regular""&8Page &P of " & N

The one recorded with the Macro Recorder has the "N" encased in [] (didn't
work).
What are these "[]", how, where, and when should are they used?
Thanks
Lou
 
E

Eric White

I think you may be confusing the special codes that Excel uses for inserting
data (page no., total pages, date, etc.) into headers/footer with the codes
Excel VBA uses.

If you look in the page setup for an Excel worksheet, the page number code
shows as "[&Page]". However, the special code that you must use in Excel VBA
is "&P" (note no space between & and P). If I understand what you're trying
to do, you want to put "Page x of y" in your right header. In Excel VBA, you
would write the string "Page &P of &N". The "&" tells Excel the next
character is a special code.

For more information, search for "Formatting Codes for Headers and Footers"
in the VBA help files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top