We help IT Professionals succeed at work.

Activate a macro if a given cell chages value (Private Sub)

bearblack asked
I have tried entering the below and it just does not work within the Sheet1 code (Worksheet Change) and I do not understand why. This is a new requirement for me and it is holding up a process that is suppose to be done by end of week.

Thanks for the help in advance
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rg As Range, cel As Range
    Dim strFormat As String
    Set rg = Intersect(Target, Cells(6, 6))
    If rg Is Nothing Then Exit Sub
    If Cells(6, 6) <> "" Then
        Cells(6, 6).FormulaR1C1 = "=R[-2]C*12" 'simple test code
    End If
End Sub

Open in new window

Watch Question

Works for me when I type something into F6. Could events have been turned off?
bearblackGlobal Program Manager


where would that be?
Add this line at the beginning and then see if it works. And check code is in the correct sheet module.

Application.EnableEvents = True
bearblackGlobal Program Manager


that worked thanks -- Can you call a sub from this as well or does all your code you want to use be inserted in the private sub
No, you can call subs from that code. Might be best now to remove that enablevents line.