I'm rather new to Excel programming, but I'm having problems doing what appears to something very simple. I want a formula to return the value of a calculation, AND set some values in some other cells. I've simplified down to two lines of code and the second assignment statement is causing me grief when I type the following in Cell A1
=MyFunc()
Function MyFunc() as Integer
MyFunc = 1
ActiveSheet.Range("A5").Value = 1
End Function
Error Returned :
Error 1004
Application-defined or object-defined error
Is this not valid? Or am I missing the boat on what you can do in Formulas?
This code works great if it was Sub, but I also can't figure out how to run the Sub as a formula. It appears Subs can only be run from menus, controls, etc... or through code.
Thanks for any help I can get.
=MyFunc()
Function MyFunc() as Integer
MyFunc = 1
ActiveSheet.Range("A5").Value = 1
End Function
Error Returned :
Error 1004
Application-defined or object-defined error
Is this not valid? Or am I missing the boat on what you can do in Formulas?
This code works great if it was Sub, but I also can't figure out how to run the Sub as a formula. It appears Subs can only be run from menus, controls, etc... or through code.
Thanks for any help I can get.