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
 

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

Similar Threads

Combine macros variable help 2
Stop Command Question 4
Opening a file stops a Macro 2
Automatize chart building 1
Macro Related to Paste Values 2
Assign Macro 1
Auto-start macro 2
Macro Data Entry Validation 4

Back
Top