Run A Macro based on changes in cell

  • Thread starter Thread starter Pete
  • Start date Start date
P

Pete

I want to be able to run a existing macro on a spreadsheet
I created, based on the information in cell "D11" being <>
4.

I know this can be done, but I am not sure what the code
should look like in order for it work properly.

One note that I don't know if it matters or not, but cell
D11 has a formula assigned to it.

Any help is appreciated
Pete
 
Try this

Place the code in the Sheet module

Right click on a sheet tab and choose view code
Paste the code there
Alt-Q to go back to Excel

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("D11") <> 4 Then
testsub
End If
End Sub

Sub testsub()
MsgBox "Hi"
End Sub
 
right click on the sheet tab and select View code

At the top of the resulting module (the sheet module), in the left dropdown
select Worksheet and in the left dropdown select calculate.

this will put in a sub declaration like:

Private Sub Worksheet_Calculate()

End Sub


You can put in code like
Private Sub Worksheet_Calculate()
if Range("D11").Value <> 4 then
mymacro
End If
End Sub


This will run your macro everytime there is a calculate event and D11 is <>
to 4. I imagine that is not exactly what you want - perhaps only when it
changes from 4 to <> to 4, but you haven't supplied that type of
information.
 
Back
Top