Archive of Mr Excel Message Board


Back to Forms in Excel VBA archive index
Back to archive home

#VALUE errors

Posted by gary on January 29, 2002 9:26 AM
I'm lost, I'm trying to set the contents of a cell in vba

Here's the function:

Public Function aa()
Cells(5, 1).Value = 999
aa = 0
End Function

It always returns a #VALUE error when called.

If I comment out the Calls statement, it returns 0

this is excel 2000

I've tried samples directly from the help files, and always get the #VALUE error when trying to set the contents of a cell

Gary


Check out our Excel Resources

Re: #VALUE errors

Posted by Larry Kramer on February 10, 2002 5:58 PM

if you want the cell to have the formula "=aa()":

Public Function aa()

aa=999

end function

You should not try to stuff a cell with a command in a function; all a function can do is return a value that will substituted for the function call in the cell's formula.

The cells(5,1)=999 command belongs in a SUB, not a function.

Or am I missing something?


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.