Trying to build a macro in Excel, unfortunately our reporting system generates inconsistent sheet tab names – so referencing a specific name only works some of the time.
Example:
Range("A2").Select
ActiveWindow.SmallScroll Down:=-6
ActiveWindow.FreezePanes = True
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Non-var Cr sects have Cr Hr"
Sheets("Page1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AL$12286").AutoFilter Field:=18, Criteria1:= _
"=None", Operator:=xlOr, Criteria2:="=OR"
Occasionally the “Page1” will be “Page1_2” – is there a basic IF THEN statement that would select whichever is available without error? I looked and found similar questions but couldn’t quite convert the applicability to my unique situation. I’m not outstanding with VBA, full disclosure. Not sure if I should put an IF THEN statement at the beginning of this rather long macro or use it for each individual instance in which the dynamic reference comes up.
Thanks in advance!
I’ve tried some very simple IF statements encompassing all the code, but maybe I should have the IF THEN statement in front of each individual occurrence of the dynamic reference.
Tristan Cassel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.