Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Can we take a look at what code you currently have for your macro? –  Jason Bristol Jul 10 '13 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 –  dev Ramkoomar Jul 11 '13 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 –  dev Ramkoomar Jul 11 '13 at 4:17
add comment

1 Answer

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.