Changing worksheet cells from inside a function

  • Thread starter Thread starter Antek Laczkowski
  • Start date Start date
A

Antek Laczkowski

Hi
The following code in VB (excel 2000):
----------- start code
function f(x as double) as double
cells(1,1) = "A"
f = x + 2
end function
----------- end code

produces #ARG error when inserted into a worksheet.
The offending line is:
cells(1,1) = "A"
Does it mean I can't change worksheet cells from inside
a function ? But macros do it.
What I'm doing wrong, or is there a way around ?

Best greetings
Antek, Warsaw, Poland
 
Hi Antek,

A function, when used in a worksheet, cannot change or alter another cell.
 
Exactly that. A function can return a value, but not change worksheet or
cell attributes. So only the cell with the formula gets affected.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Back
Top