ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   using the macro in Worksheet function (https://www.excelbanter.com/excel-worksheet-functions/238874-using-macro-worksheet-function.html)

jannot

using the macro in Worksheet function
 
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.

Bernard Liengme[_3_]

using the macro in Worksheet function
 
A function can do one thing: it can return a value
It cannot run a macro
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email


"jannot" wrote in message
...
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.




Jacob Skaria

using the macro in Worksheet function
 
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 tabView 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
---------------
Jacob Skaria


"jannot" wrote:

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.


Gord Dibben

using the macro in Worksheet function
 
If B4 is a calculated value use

Private Sub Worksheet_Calculate() event instead of Change event.


Gord Dibben MS Excel MVP

On Tue, 4 Aug 2009 09:23:01 -0700, Jacob Skaria
wrote:

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 tabView 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
---------------
Jacob Skaria


"jannot" wrote:

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.




All times are GMT +1. The time now is 05:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com