Action on sheet Selection

  • Thread starter Thread starter jpizzle
  • Start date Start date
J

jpizzle

Hello everyone, Im back for another probably easy question. How would
get excel to preform a certain action, or macro, when a specific shee
is selected? Thanks again everyone
 
Dear Sir,

Try this:

Place the code below in "ThisWorkbook" Module of your workbook

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim SheetName As String
SheetName = "Sheet1"

If Sh.Name = SheetName Then
'Your code goes here
MsgBox "You Selected Sheet: " & Sh.Name
End If
End Sub

What you need to do:
Replace SheetName with the name of the sheet you want to capture and
place you code where it says "Your Code Here". Remenber to remove the
msgbox instruction I placed for ilustration.

What it does:
When you select Sheet1 (Name I selected for SheetName) will display a
message with the name of the selected sheet.

How it works:
When you select a sheet the "Workbook_SheetActivate" event fires.
Excel passes the sheet name through the variable "Sh".

SheetName = "Sheet1" --> Here you replace "Sheet1" with the name of
the sheet you want to capture.


If Sh.Name = SheetName Then
'PLACE YOUR CODE HERE
End If

Please, let me know if that solve your ploblem.

regards.

Juan Carlos
 
Previous post is better, put the code in the specific sheet's module, that
way if the user changes the sheet name, it will not cause the code to fail.
Bill
 

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

Back
Top