[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 770
  • Last Modified:

Worksheet_SelectionChange

Hello Experts - Is it possible to control any sheet in workbook off one module with code
Worksheet_SelectionChange(ByVal Target As Excel.Range)? As somebody here advised me earlier, rather than copying same macro to each sheet I could use this avenue instead.
For example, I want to do this when click on any cell in sheet1 through Sheet20  ...
Worksheet_SelectionChange(ByVal Target As Excel.Range)
msgbox activecell.value

Cheers, V
0
NewToVBA
Asked:
NewToVBA
  • 3
1 Solution
 
Wayne Taylor (webtubbs)Commented:
I think what you mean is the Workbook_SheetSelectionChange event. The code for this would go in the ThisWorkbook module.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

End Sub

Open in new window


One of the parameters of the event is the sheet ("Sh"), so if need be you can easily determine what sheet is the active one.

Wayne
0
 
NewToVBAAuthor Commented:
Hi Wayne -  I am not able to "wake up" the code. I place it in Module1, and click on sheets with no effect. Must be doing something wrong...

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
MsgBox ActiveSheet.Name
End Sub

tks, V
0
 
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Read Wayne's post again.

>> The code for this would go in the ThisWorkbook module.
0
 
NewToVBAAuthor Commented:
Thank you, Wayne!
0
 
NewToVBAAuthor Commented:
Hi Teylyn - thank you for your comment
cheers, v
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now