Forum Discussion
Lukie_Dukie
Apr 23, 2020Copper Contributor
Why does copying cells work in a Sub but not in a Function?
Hello, I am new to VBA and have come across a problem: why does copying values from one cell to another work in a Sub but not in a Function? I have simplified the problem to this description ...
- Apr 23, 2020
Lukie_Dukie I guess that's because a function works inside a cell. Just like you can't put e.g. =SUM(A1:A10) in cell A11 and have the result returned in B11. But, with a SUB you can say "sum A1:A10 and put the result somewhere else".
Riny_van_Eekelen
Apr 23, 2020Platinum Contributor
Lukie_Dukie I guess that's because a function works inside a cell. Just like you can't put e.g. =SUM(A1:A10) in cell A11 and have the result returned in B11. But, with a SUB you can say "sum A1:A10 and put the result somewhere else".
- Lukie_DukieApr 24, 2020Copper Contributor
Riny_van_Eekelen- Thank you, it is the first time I have seen that as an explanation of the difference between functions and subs - I must be trying to learn VBA from the wrong resources!