ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how to run a macro from a formula? (https://www.excelbanter.com/excel-discussion-misc-queries/33769-how-run-macro-formula.html)

davidhub

how to run a macro from a formula?
 
I need to define a formula to run a predefined macro as a result of a logical
comparision. Please help.

Tom Ogilvy

You can make you macro a function and then use it in your formula. Be aware
that macros used in this fashion can only return a value to the cell
containing the function - they can not format cells, change values in cells
or otherwise alter the Excel environment.

--
Regards,
Tom Ogilvy

"davidhub" wrote in message
...
I need to define a formula to run a predefined macro as a result of a

logical
comparision. Please help.




moi

Add a function and put that in your worksheet IF-statement, like:

Public Function cellFunctionFirst(cellText As String) As String
Call thenModule(cellText)
cellFunctionFirst = cellText
End Function

Private Sub thenModule(cellText As String)
cellText = cellText & " text string added by macro."
End Sub

From the function call the module and do the work there.
Only thing is, that a function always gives back a value and you might not
want that. So then it's better to add a worksheet event that keeps listening
and launches another more macro (or not) after your function changed a cell
with a certain result.



"davidhub" schreef in bericht
...
I need to define a formula to run a predefined macro as a result of a
logical
comparision. Please help.





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

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