How to run different macros on selected work sheets

AjayCh

New Member
Joined
Apr 20, 2015
Messages
14
Hi ,

I am having work book with different work sheets.

I am having macros for different worksheets.
i AM HAVING SHEETS (UsageTracking, DeveloperUsage,DMNE-0418, SAS-0418,SOD-0418, DMNE-0411,SAS-0411,SOD-0411...so on)
I am having a macro for all work sheets starting with SOD,
another macro for worksheets starting with DMNE,another macro for work sheets starting with SAS.
I am having one macro for Usage tracking.

My requirement is when i click on the work sheet starting with SOD,how can run the macro related to SOD.Similarly in all the sheets.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You could use something like this in the "ThisWorkbook" object:

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Select Case True
    Case Sh.Name Like "SOD*"
        Call SODMAcro
    Case Sh.Name Like "DMNE*"
        Call DMNEMacro
    Case Sh.Name Like "SAS*"
        Call SASMacro
    Case Sh.Name = "UsageTracking"
        Call TrackingMacro
    Case Else
        MsgBox "Sheet does not have a macro"
End Select


End Sub

Here's my module where all the macros are stored

Code:
Sub SODMAcro()
MsgBox "SOD"
End Sub
Sub DMNEMacro()
MsgBox "DMNE"
End Sub
Sub SASMacro()
MsgBox "SAS"
End Sub
Sub TrackingMacro()
MsgBox "Tracking"
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,903
Members
449,477
Latest member
panjongshing

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