ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Running a Macro from a Spreadsheet Function (https://www.excelbanter.com/excel-worksheet-functions/176210-running-macro-spreadsheet-function.html)

Patrick (GVC)

Running a Macro from a Spreadsheet Function
 
Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.

Gord Dibben

Running a Macro from a Spreadsheet Function
 
You can't run a macro from an Excel IF function.

You may be able to run a macro from event code that is triggered by the results
of an IF calculation.

More details would be in order but here is sample sheet event code that runs on
the results of an IF

A1 fomula is =B1 * C1

Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("A1")
If .Value < 144 Then
MsgBox "Please be advised that A1 does not equal the correct amount."
'Call "your macro name" to be used instead of the msgbox
End If
End With
stoppit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP




On Sat, 9 Feb 2008 16:19:00 -0800, Patrick (GVC) <Patrick
wrote:

Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.



Stan Brown

Running a Macro from a Spreadsheet Function
 
Sat, 9 Feb 2008 16:19:00 -0800 from <?B?UGF0cmljayAoR1ZDKQ==?
= <Patrick :
Does anyone know a method of calling/running a macro from within a cell
function (e.g. a logical IF function)? I am currently using XP Office with
Excel 2002.


Make it a user-defined function. As far as I know, a function can
contain any code that you could put into a macro.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com
A: Maybe because some people are too annoyed by top posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?


All times are GMT +1. The time now is 07:39 PM.

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