Starting a macro with the IF function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

is there any way to start a macro, once the contition of the if-function in
the worksheet turns true???

greetings and thankst

THW
 
No, but you could use event code to monitor the cell

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$H$1" Then
With Target
'do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 
Good afternoon Thw

A cell cannot kick off a macro, but you could use an event procedure t
do something when the cell changes - paste this code into your workshee
event pane and replace my msgbox with your code. And remember that m
code is checking for the value of cell A1 being false - your pos
doesn't state which cell you want to watch.

Private Sub Worksheet_Calculate()
If Range("A1") = True Then
MsgBox "Cell A1 is true."
End If
End Sub

HTH

Dominic
 
hi dominicb

thank you for your reply, but my problem is not to be notified if the value
of a cell IS true, i need to be notified WHEN it's value changes to true

greetings
THW
 
I'll try again specifically

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$H$1" Then
With Target
if .value then
Msgbox "true"
endif
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top