Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Modify cell from function

Is it possible to update cells from within a function? I know you can read from them but updating gives the following (really unhelpful) error:

Run-time error '1004': Application-defined or object-defined error

Here is the code for the function:

Public Function Test() As Integer
Range("A2").Value = "Hello"
End Function

The formula from the cell I am calling it from is "=Test()".

NOTE: The error message does not actually pop up when run. You get #VALUE! in the calling cell and the value Hello is not written. What I did for the error was put a break-point on the Range line, then execute the line in the Immediate window.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Modify cell from function

Jason,

With functions, you can only read in information and write back an answer.
You cannot change cells (other than writing back an answer), change display
settings or whatever else. You were attempting to change A2. If you are in
A3 and using a function, you cannot change A2. You can only write an answer
to A3.

If you code was like this....

Public Function Test() As String
Test = "Hello"
End Function

Then you could write in any cell =Test() and get back "Hello".

Note that the function is a STRING and not an INTEGER (see yours below) as
"Hello" is a string.

Regards,
Kevin




"Jason Callas" wrote in message
...
Is it possible to update cells from within a function? I know you can read
from them but updating gives the following (really unhelpful) error:

Run-time error '1004': Application-defined or object-defined error

Here is the code for the function:

Public Function Test() As Integer
Range("A2").Value = "Hello"
End Function

The formula from the cell I am calling it from is "=Test()".

NOTE: The error message does not actually pop up when run. You get #VALUE!
in the calling cell and the value Hello is not written. What I did for the
error was put a break-point on the Range line, then execute the line in the
Immediate window.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Modify cell from function

Hi Jason:

A worksheet function can only return a value to the calling cell, it cannot
modify any other cells.

Regards,

Vasant.

"Jason Callas" wrote in message
...
Is it possible to update cells from within a function? I know you can read
from them but updating gives the following (really unhelpful) error:

Run-time error '1004': Application-defined or object-defined error

Here is the code for the function:

Public Function Test() As Integer
Range("A2").Value = "Hello"
End Function

The formula from the cell I am calling it from is "=Test()".

NOTE: The error message does not actually pop up when run. You get #VALUE!
in the calling cell and the value Hello is not written. What I did for the
error was put a break-point on the Range line, then execute the line in the
Immediate window.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Modify cell from function

I was the answer I was thinking. Just wanted a confirmation. Thanks.

- Jason

"Kevin Stecyk" wrote in message
...
Jason,

With functions, you can only read in information and write back an answer.
You cannot change cells (other than writing back an answer), change

display
settings or whatever else. You were attempting to change A2. If you are

in
A3 and using a function, you cannot change A2. You can only write an

answer
to A3.

If you code was like this....

Public Function Test() As String
Test = "Hello"
End Function

Then you could write in any cell =Test() and get back "Hello".

Note that the function is a STRING and not an INTEGER (see yours below) as
"Hello" is a string.

Regards,
Kevin




"Jason Callas" wrote in message
...
Is it possible to update cells from within a function? I know you can read
from them but updating gives the following (really unhelpful) error:

Run-time error '1004': Application-defined or object-defined error

Here is the code for the function:

Public Function Test() As Integer
Range("A2").Value = "Hello"
End Function

The formula from the cell I am calling it from is "=Test()".

NOTE: The error message does not actually pop up when run. You get #VALUE!
in the calling cell and the value Hello is not written. What I did for the
error was put a break-point on the Range line, then execute the line in

the
Immediate window.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify search function Dinesh Excel Worksheet Functions 3 March 18th 09 02:26 AM
How do I modify the autofit function in Excel? NadineWoj Excel Discussion (Misc queries) 2 February 22nd 06 10:25 PM
Can I modify cell attributes (font,color etc.) based on function . TicklePig Excel Discussion (Misc queries) 4 December 4th 05 04:23 AM
Can I modify a Hyperlink with a function? barrfly Excel Discussion (Misc queries) 7 June 2nd 05 12:03 AM
to modify cells from a function Pierre Laporte Excel Programming 1 July 10th 03 02:11 PM


All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"