Is it possible to run a macro from within a formula?
eg =If(A1="yes", run macro, " ")
I hope it is! please help me here
Thanks![]()
Is it possible to run a macro from within a formula?
eg =If(A1="yes", run macro, " ")
I hope it is! please help me here
Thanks![]()
From some brief tests I did, I think it depends on what kind of procedure you're using. If your "macro" does things that allow it to be defined as a "function" procedure, then you can use it inside of an IF function like that.
If your macro does things that force you to define it as a sub procedure, I don't believe you can call a sub procedure from within an if function like that. In that case, I think it would be better to define a calculate event sub procedure (or whatever event you need the sub to run on). The first line of this sub procedure would then check the value of A1 and respond accordingly. I think this is about how it would look:
Sub Worksheet.Calculate()
If sheets(1).cells(1,1)<>"yes" then
sheets(1).cells(2,1)=""
exit sub
end if
macro code if cells(1,1)="yes"
end sub
thanks - appreciate it
my macro is simple - to hide colums is cell = x
but what do i put in the formula to invoke the macro?
hiding a column isn't something you can do from a function.
I'm not sure if conditional formatting will allow hiding a column as one of the formats it can do.
If conditional formatting won't work, then you'll need a macro like I suggested above. In my above example, the macro is supposed to be automatically called everytime the worksheet calculates. You could also associate the macro with other events (open, close, etc.). Or you could link to macro to a toolbar button or keyboard shortcut and run the macro manually whenever you want to run the macro.
thanks for your help - I am playing with your macro now
appreciated as ever
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks