View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Trevor Shuttleworth Trevor Shuttleworth is offline
external usenet poster
 
Posts: 1,089
Default Assigning cell values within a VBA program

Chris

a Function can only return a value to the cell it is in; it cannot affect
another cell or the Excel environment.

Regards

Trevor


"Chris Burrows" wrote in message
...
Why doesn't this function work?

Function Zemax()
Worksheets("Sheet1").Range("A1").Formula = "=2+2"
Zemax = 3
End Function

If I execute it within the IDE using F5, I get cell A1 set correctly.
If I comment out the second line, and call it as a function reference

within the spreadsheet it sets the current cell to 3.
If I don't comment it out, it doesn't set cell A1, and returns a #VALUE

error.

What gives?????