View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
PBezucha PBezucha is offline
external usenet poster
 
Posts: 120
Default Run a macro from within a function

Just to prevent misapprehension:

A VBA FUNCTION can call a SUB. The function can be triggered by a change of
an argument, for example just your deciding yes/no (as Boolean variable). The
SUB can take values even from elsewhere, not only from the inner of the
function, but €“ there is the hell of restriction €“ it cannot pass any values
other than over this function output.

Remark: You are allowed to place a MsgBox into a function body, where you
can execute your deferred deciding step.

Regards
--
Petr Bezucha


"BK523" wrote:

Thabnk you for your reply. It looks like this is a good approach & I will
take some time to develop it.



"Gord Dibben" wrote:

Formulas cannot run macros.

You could use event code to run a macro when C3 is changed to yes.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo stoppit
Application.EnableEvents = False
If Target.Address = "$C$3" And Target.Value = "yes" Then
Call macroname
End If
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 13 Jan 2009 11:38:06 -0800, BK523
wrote:

I would like to launch a macro from within an "IF" statement.
Example: Cell C3 is a "yes / no" type cell. Cell C4 would evaluate the
contents of C3 and launch a macro if C3="Yes"

Can this be done?