Run Macro when click on different tab in Excel

S

Supe

Is there a way to set up a macro to run when you click on a different tab in
the Excel sheet? I have a data tab where I pull my data tab that I have set
up a macro to format some of the data in that pull. Would like that macro to
run when I click on the pivot tab. Is this possible?
 
G

Gord Dibben

Copy/paste this to the pivot tab module.

Private Sub Worksheet_Activate()
macroname
End Sub


Gord Dibben MS Excel MVP
 
S

Supe

There are 5 Modules listed. I have two macros I want to activate:

findandreplace
FormatDate

Do I need to list each macro in a separate code? Which module would I put
it in? My findandreplace macro is in Module 3 and my FormatDate macro is in
Module 5.
 
G

Gord Dibben

Right-click on the Pivot Tab.

Select "View Code"

Copy/paste this code to the sheet module that opens.

Private Sub Worksheet_Activate()
findandreplace
FormatDate
End Sub

Leave the two macros where they are in the general modules.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top