ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   =If(Macro) (https://www.excelbanter.com/excel-discussion-misc-queries/110301-%3Dif-macro.html)

AntnyMI

=If(Macro)
 
Is there a way to incorporate a macro into an If/Then statement?
For example, in Cell A1: =If(B1="Johnson",SortJ,"")
<<where "SortJ" is the name of the recorded macro


Tom Ogilvy

=If(Macro)
 
if you make SortJ a function

Sub SortJ()

End Sub

to

Function SortJ()


SortJ = "SomeValue"
End Function


So as the last line or at least some line, you assign a value for SortJ to
return to the cell for display.

If you have any selecting in the recorded macro, you will need to eliminate
that.

You will not be able to change any cells in any way - only return a value to
SortJ which will be displayed by your function. Just like a built in
function.

--
Regards,
Tom Ogilvy


"AntnyMI" wrote in message
oups.com...
Is there a way to incorporate a macro into an If/Then statement?
For example, in Cell A1: =If(B1="Johnson",SortJ,"")
<<where "SortJ" is the name of the recorded macro





All times are GMT +1. The time now is 01:27 PM.

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