0

When I run a macro, the value in cell AB2 changes. I want another macro named copyStuff to run automatically when the value in cell AB2 changes to 6. Please help.

3
  • Can we take a look at what code you currently have for your macro? Jul 10, 2013 at 18:23
  • Thanks a lot.I have been able to write the macro using examples on the net.In fact I have combined 3 macros into 1.I have added the codes for the second and third macros to the first one and it is working.The code for the second macro to copy values to subsequent rows on sheet 2 when value of cell AB2 in sheet 1 is 6 is as follows Jul 11, 2013 at 4:07
  • Thanks a lot.I have been able to write the macro using examples on the net.In fact I have combined 3 macros into 1.I have added the codes for the second and third macros to the first one and it is working.The code for the second macro to copy values to subsequent rows on sheet 2 when value of cell AB2 is 6 is as follows. If Range("ab2").Value = 6 Then Range("Ai16:an16").Copy Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) End If And the code to run the macro several times 'Sub GG() Dim i As Long For i = 1 To Range("z1") newmac Next End Sub Jul 11, 2013 at 4:17

1 Answer 1

0

You can use the Worksheet_Change event to trigger your code. To do this open the VBA editor window (press Alt+F11). In the project explorer, double click the sheet on which you want to monitor AB2 (listed under Microsoft Excel Objects).

enter image description here

Then, paste in the following code. If copyStuff is in a separate module, this should work right away.

Private Sub Worksheet_Change(ByVal Target As Range)
'Check if changed range includes AB2. If so, check value of AB2.
If Not Intersect(Target, Me.Range("AB2")) Is Nothing Then
    If Me.Range("AB2").Value = 6 Then
        Call copyStuff
    End If
End If
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .