using the macro in Worksheet function

  • Thread starter Thread starter jannot
  • Start date Start date
J

jannot

Hi,
I try to use the macro in one condition of "IF"
If(B1=4,Macro1,"not necessary")
I don't know if is posibile run Macro1.
somebody can help me ?

Thanks in advance.
 
A function can do one thing: it can return a value
It cannot run a macro
best wishes
 
As Bernard mentioned the macro cannot be trigerred from a formula.
However you can make use of the worksheet change event to call the macro
when B4 is 4. Try the below. From sheet tab>View code and paste the below
code...now if the value in B4 is entered as 4 macro1 is initiated.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
If Target.Value = 4 Then Call Macro1
End If
Application.EnableEvents = True
End Sub

If this post helps click Yes
 
If B4 is a calculated value use

Private Sub Worksheet_Calculate() event instead of Change event.


Gord Dibben MS Excel MVP
 
Back
Top