Link to home
Start Free TrialLog in
Avatar of Bright01
Bright01Flag for United States of America

asked on

Macro with "If" Statement for choosing which Macro to run

EE Pros;

I have three tabs on in a Workbook -- Sheets 1, 2 and 3.  Only Sheet 1 is visable; the other two are hidden.  I have built a Macro on Sheet 1 that will "expose" EITHER Sheet 2 or 3 but not both at the same time.  Here is my challenge....;  I need a Macro that can be fired from Sheets 2 OR 3 that will hide them and return you to Sheet 1 (.Active).  What I don't know is how to use an "if" statement in a macro, and what do I use to identify if it's Sheet 2 or Sheet 3 that is exposed (the Sheet name?)?  I would envision something like;

=if("Sheet2",xlvisibility=.hidden,Sheet3.xlvisibility=.hidden)
.activate "Sheet1"

But only as a "macro newbee"!

B.
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

How are you triggering the macro? If it's from the sheet in question, then you can simply refer to activesheet.
Avatar of ChrisKader
ChrisKader

Sub Hide()

ActiveSheet.Visible = xlSheetHidden

End Sub
Avatar of Bright01

ASKER

I do apologize.  I have this backwards.  

When the model starts up, I have a single Sheet appear (Sheet1, all others are hidden).  Based on a selection, a macro fires that brings up EITHER Sheet 2 or Sheet 3. From Sheet 2 or 3, I have a macro at the top of each Sheet (in a module because either Sheet can use it) that exposes Sheet 4.  My problem is in closing Sheet 4 and returning to EITHER Sheet 2 or 3 depending on which one is open.  I need Sheet 4 to determine if Sheet 2 or Sheet 3 is open and that is the Sheet to return to while hiding itself.

Make sense?  Again, sorry for the initial confusion.

B.
SOLUTION
Avatar of ChrisKader
ChrisKader

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys.  Very sorry for the delay..... I have had the worst case of the flu that I think I have ever had.  Anyway, getting back into it and your solution(s) worked perfectly.

Again, much thanks!

B.