Cannot write to cell

smhodge

New Member
Joined
Oct 5, 2017
Messages
2
This is totally baffling me, and should be incredibly simple. I have this test function:

Function TestFunction(arg)
Range("Q17").Value = arg ' Does not work
TestFunction = arg
End Function

If I execute it in a cell with the "Range" line commented out it works fine and places "arg" into the cell where the function was executed from. However, if I uncomment the "Range" line (as shown), "arg" does not get placed in cell "Q17" and the function returns with #VALUE ! in the cell where the function was executed from.

What I am missing here? Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
To complement my previous post
Observe in the Summary of the article (link above) :
"... when called by a formula in a worksheet cell."

M.
 
Upvote 0
Thanks. Is the work around to simply make it a subroutine and then call that from the function?
 
Upvote 0
Thanks. Is the work around to simply make it a subroutine and then call that from the function?

We need more details.
What exactly are you trying to do?
Why use a function to change the value of cell Q17 instead of doing this in a Sub?

M.
 
Upvote 0
Thanks. Is the work around to simply make it a subroutine and then call that from the function?
There is no workaround.

A formula written in A1 (whether using standard functions or UDFs) can ONLY return a value to A1. It CANNOT modify any other cell.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top