VBA Else statement in MACRO

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
735
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings,

I have a basic MACRO that inserts a header. I think I would need an "Else" statement that if a "0" is in Cell A1 on Sheet "Settings" I need the header to be "DEPARTURES (ZULU)" any other integer in A1 in Sheet "Settings" the original text described below is fine. The active sheet is named Schedule though I can't see what difference that would make.

VBA Code:
Sub Header2()
        
    ActiveSheet.PageSetup.CenterHeader = _
        "&""Times New Roman,Bold""&20 DEPARTURES (LOCAL) "
        End Sub

Thank you very much indeed.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
MAybe this
VBA Code:
Sub Header2()
If Cells(1, 1) = "0" Then
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (ZULU)"
Else
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (LOCAL) "
End If
 End Sub
 
Upvote 0
MAybe this
VBA Code:
Sub Header2()
If Cells(1, 1) = "0" Then
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (ZULU)"
Else
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (LOCAL) "
End If
 End Sub
The Cell (1,1) is on a different worksheet. The active sheet is named “Schedule”, and the sheet where the integer is located is named “Settings”.

Thank you
 
Upvote 0
OK...try
VBA Code:
Sub Header2()
If Sheets("Settings").Cells(1, 1) = "0" Then
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (ZULU)"
Else
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (LOCAL) "
End If
 End Sub
 
Upvote 0
OK...try
VBA Code:
Sub Header2()
If Sheets("Settings").Cells(1, 1) = "0" Then
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (ZULU)"
Else
    ActiveSheet.PageSetup.CenterHeader = "&""Times New Roman,Bold""&20 DEPARTURES (LOCAL) "
End If
 End Sub
Thank you; I can’t check now, but I’m sure it will work. You’ve help me before and you’re pretty solid. Thank you.
 
Upvote 0

Forum statistics

Threads
1,203,397
Messages
6,055,165
Members
444,767
Latest member
bryandaniel5

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
Back
Top