• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Execute Macros From Formulas (Or Cell Value)

indi visual

Junior Member
I would like to execute macros if specific cells change.

I have 25 cells I would like to apply this to.

After hours upon hours of failure, I would really just like to know if this even possible.

If "Z1" equals "1", then run macro
If value is not "1" do nothing
If "Z2" equals "2", then run macro
If value is not "2" do nothing
 
yes, you'll want to use worksheet events.
in the vba editor, double click on the worksheet that contains the cells you want to check.

At the top of the editor, there are 2 dropdown boxes, in the left box, select "Worksheet" and in the right, select "Change". This will create a new sub procedure called:

Private Sub Worksheet_Change(ByVal Target As Range)

Put the following code in the procedure:

Code:
If Intersect(Target, Range("Z1:Z2")) Is Nothing Then
    Exit Sub
Else
    Select Case Target.Address
        Case "$Z$1"
            If Target.Value = 1 Then RunMacro1
        Case "$Z$2"
            If Target.Value = 2 Then RunMacro2

    End Select
End If

this checks if the cell that has changed is within the range of cells that you want to check. it then checks which cell changed, and compares it's value to the value want to trigger the new macro. Obviously, you'll need to change the "RunMacro" parts above to the actual names of your macros.
 
Back
Top