Start Macro when a speecific sheet is active

CliffMc

New Member
Joined
May 23, 2003
Messages
15
HI,

I have been trying to use a "Private Sub" to start a Macro when I select a specific worksheet with in the workbook. But I am having trouble with the syntax. Not sure if I should be using WorkSheet_SelectionChange or WorkBook_sheetchange.

Here are a couple of variations that i have tried but no luck

Private Sub Worksheet_selectionChange(ByVal target As Excel.Sheet)
If target.Address = "Reconciliation" Then Call Recon
End Sub

And

Private Sub Workbook_Changesheet(ByVal target As Excel.Sheet)
If target.Address = "Reconciliation" Then Call Recon
End Sub

Any help would be greatly appreciated

Thanks

Cliff
:oops:
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Try:

Private Sub Worksheet_Activate
If Your Condition Then
End If

Hope that helps,

Smitty
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Right click the tab for sheet Reconciliation and choose View Code. In the left hand dropdown choose Worksheet. You will get this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

which is the procedure stub for the default event and which you can delete. In the right hand dropdown choose Activate. You will get this:

Code:
Private Sub Worksheet_Activate()

End Sub

to which you should add:

Code:
Call Recon
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,610
Members
414,080
Latest member
penguin23

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
Top