ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro when validation field is activated (https://www.excelbanter.com/excel-programming/366615-run-macro-when-validation-field-activated.html)

Icaro

Run a macro when validation field is activated
 
Hello.

Is it possible to make a macro runs when a cell with a validation data
is activated, without using the ToolsMacroMacroRun option?


Otto Moehrbach

Run a macro when validation field is activated
 
Yes. Use the Worksheet_SelectionChange event macro. That macro fires
whenever any cell selection is made. The code you write in that macro will
limit action to the selection of just that one cell. Assuming the Data
Validation cell is A1, and the macro you want to run is named MyMacro, the
macro would look like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address(0, 0) = "A1" Then
Call MyMacro
End If
End Sub
Note that this macro must be placed in the sheet module of that sheet that
has the A1 Data Validation cell. To access that module, right-click on the
sheet tab. select View Code, and paste this macro into that module. "X" out
of the module to return to your sheet. HTH Otto
"Icaro" wrote in message
oups.com...
Hello.

Is it possible to make a macro runs when a cell with a validation data
is activated, without using the ToolsMacroMacroRun option?





All times are GMT +1. The time now is 05:47 PM.

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