VBA Case Question

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hi All,

How do I write in code the following verbal:

If opens on Sheet(1) or Sheet(8) then Call MySubA.

If opens on Sheet(10) then Call MySubB

Many thanks in advance!

R/
Pinaceous
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Your wanting to run script named "MySubA" any time you activate Sheet (1) or Sheet(8) is that what you want?

And any time Sheet (10).activated you want to run script named "MySubB"
 
Upvote 0
Yes, that is correct.

The workbook should only be opened to one of these sheets, where I want an independent Sub to be run for each sheet when opened, respectfully.

Thank you!
 
Upvote 0
Are you wanting the script to run any time the "Workbook" is Opened or any time a Worksheet is activated?

And if when "Workbook" is opened then what worksheet do you want to be activated when the Workbook is opened.

Please give more details.
 
Upvote 0
Is this the sort of thing you're after
Code:
    Select Case ActiveSheet.Index
        Case 1, 8
            Call MySubA
        Case 10
            Call MySubB
    End Select
 
Upvote 0
Hi Fluff,

Yes, that is what I'm looking for.

Thanks very much!

Respectively,
Pinaceous
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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