ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro by sellecting a cell (https://www.excelbanter.com/excel-programming/389068-run-macro-sellecting-cell.html)

looper

Run a macro by sellecting a cell
 
Is there a way to initiate a macro by simply sellecting a cell.

Thank you

JW[_2_]

Run a macro by sellecting a cell
 
In the Microsoft Excel Objects folder within your VBA Project, select
the sheet that contains the cell that you want to run the macro.
Place the code in the Worksheet_SelectionChange event of that sheet.
Or, you could have the main code stored in a seperate module and
simply call it from the selectionchange event. Example:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$G$5" Then MsgBox "you click it!"
End Sub
--Or--
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
call ClickedSub
End Sub

HTH
-Jeff-

looper wrote:
Is there a way to initiate a macro by simply sellecting a cell.

Thank you



JW[_2_]

Run a macro by sellecting a cell
 
oops. Made a typo. To call another sub when G5 is clicked, use:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$G$5" Then Call ClickedSub
End Sub

JW wrote:
In the Microsoft Excel Objects folder within your VBA Project, select
the sheet that contains the cell that you want to run the macro.
Place the code in the Worksheet_SelectionChange event of that sheet.
Or, you could have the main code stored in a seperate module and
simply call it from the selectionchange event. Example:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$G$5" Then MsgBox "you click it!"
End Sub
--Or--
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
call ClickedSub
End Sub

HTH
-Jeff-

looper wrote:
Is there a way to initiate a macro by simply sellecting a cell.

Thank you



looper

Run a macro by sellecting a cell
 
Jeff, thank you for the response. I think i could make it work if I were more
experienced or had a little more time. What I am trying to do is to allow
inexperienced users to select from one of 10 customers that are listed in 10
different cells. Selecting the customers sets pivot filters to show specific
info for each. This process works and I currently have text boxes with
assigned macros for each customer. This works but is very cumbersome to add
new customers. That is why i am trying to initiate from cell selection.

Thanks for the help




All times are GMT +1. The time now is 11:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com