Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Gary's Student
 
Posts: n/a
Default Set a cell from within a function

I am writing a function to calculate the area of a triangle given the lengths
of the sides. If the inputs are invalid (one side too big), I want the
function to set CELL(3,3) to one. Setting CELL(3,3)=1 in the function
doesnt work. How can I accomplish this?
--
Gary's Student
  #2   Report Post  
JulieD
 
Posts: n/a
Default

Hi Gary's Student

what do you mean by "function" a "user defined function" written in VBA or a
formula in a cell in a worksheet? if the later a formula can not affect
another cell only the one it is in ... if it's a vba function then you can
using code along the lines of

Cell(3,3).value = 1

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"Gary's Student" wrote in message
...
I am writing a function to calculate the area of a triangle given the
lengths
of the sides. If the inputs are invalid (one side too big), I want the
function to set CELL(3,3) to one. Setting CELL(3,3)=1 in the function
doesn't work. How can I accomplish this?
--
Gary's Student



  #3   Report Post  
Bill Martin -- (Remove NOSPAM from address)
 
Posts: n/a
Default

JulieD wrote:

... if it's a vba function then you can
using code along the lines of

Cell(3,3).value = 1


Am I correct though that you can only do that if you're using VBA to
write a macro as opposed to a function? A VBA function can only return
a single value and not alter spread sheet cells? While a macro can
reach out and touch anything?

I'm still trying to feel my way through some of this.

Bill
  #4   Report Post  
JulieD
 
Posts: n/a
Default

Hi Bill

yes, you are correct - badly worded on my part .. .a VBA function can not
make changes to another cell whereas a sub procedure (macro) can

--
Cheers
JulieD
"Bill Martin -- (Remove NOSPAM from address)"
wrote in message ...
JulieD wrote:

... if it's a vba function then you can using code along the lines of

Cell(3,3).value = 1


Am I correct though that you can only do that if you're using VBA to write
a macro as opposed to a function? A VBA function can only return a single
value and not alter spread sheet cells? While a macro can reach out and
touch anything?

I'm still trying to feel my way through some of this.

Bill



  #5   Report Post  
JulieD
 
Posts: n/a
Default

Hi

better answer (thanks Bill)
a function can not change the value of another cell - you need to use a VBA
macro for this - for example you could code against the worksheet_change
event that if the cell with the function in it returned a 0 or whatever,
then Range(C3) needs to change to a 1.

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"Gary's Student" wrote in message
...
I am writing a function to calculate the area of a triangle given the
lengths
of the sides. If the inputs are invalid (one side too big), I want the
function to set CELL(3,3) to one. Setting CELL(3,3)=1 in the function
doesn't work. How can I accomplish this?
--
Gary's Student





  #6   Report Post  
Gary's Student
 
Posts: n/a
Default

Thank you for your very rapid response

"JulieD" wrote:

Hi

better answer (thanks Bill)
a function can not change the value of another cell - you need to use a VBA
macro for this - for example you could code against the worksheet_change
event that if the cell with the function in it returned a 0 or whatever,
then Range(C3) needs to change to a 1.

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"Gary's Student" wrote in message
...
I am writing a function to calculate the area of a triangle given the
lengths
of the sides. If the inputs are invalid (one side too big), I want the
function to set CELL(3,3) to one. Setting CELL(3,3)=1 in the function
doesn't work. How can I accomplish this?
--
Gary's Student




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
If Function: Blank cell and 0 (zero) seem to have same "value" John F Excel Worksheet Functions 1 January 6th 05 04:46 PM
#VALUE in cell but pop up function box show right number Ted Dalton Excel Discussion (Misc queries) 1 December 14th 04 03:15 PM
Function to operate on ink linked to cell Alan T Excel Worksheet Functions 0 November 20th 04 10:03 PM
Is there a function to determine whether a cell contains a formul. Christo Kriel Excel Worksheet Functions 1 November 20th 04 06:54 PM
Excel - option to extend function in cell to column kjoshua777 Excel Worksheet Functions 2 November 18th 04 01:08 AM


All times are GMT +1. The time now is 07:39 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"