Home » excel » vba – How to put an ampersand in a header/footer in Excel?

vba – How to put an ampersand in a header/footer in Excel?

Posted by: admin March 9, 2020 Leave a comment

Questions:

I am working on a header which needs an ampersand to separate two words.

Hello & World

But it ignores the & because most of the built in functions evaluate it to a value ie.

Page &[Page] of &[Pages] => Page 1 of 3

&[Time] or &T => 10:26

So, how to escape an ampersand in a header?

How to&Answers:

It turns out to be a super simple solution …

Double the && to escape from Excel trying to evaluate to a built-in function.

Same in VBA String for: hello & world

Sheet1.PageSetup.CenterHeader = "hello && world!"