Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Help with Range.("XX").Value = (Newbie)

I have a function that sums 3 values:

********
Public Function sum(UserRange) As Double

sum = 0

For Each cell In UserRange
sum = sum + cell.Value
Next cell

Range("H5").Value = 7 : THIS DOESNT WORK ???


mysum = sum

End Function
******
The call for it is in a cell (G4) , =sum(G1:G3)
I am trying to set the value of another cell in this function using
Range("H5").Value = 7,but it does nothing.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Help with Range.("XX").Value = (Newbie)

Hi David,

A user defined function (UDF) can only return
a value to the calling cell; it cannot change its
envirinment or change another cell.


---
Regards,
Norman

"David Andrews" wrote in message
news:V%z8i.1968$FU4.119@trndny02...
I have a function that sums 3 values:

********
Public Function sum(UserRange) As Double

sum = 0

For Each cell In UserRange
sum = sum + cell.Value
Next cell

Range("H5").Value = 7 : THIS DOESNT WORK ???


mysum = sum

End Function
******
The call for it is in a cell (G4) , =sum(G1:G3)
I am trying to set the value of another cell in this function using
Range("H5").Value = 7,but it does nothing.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Help with Range.("XX").Value = (Newbie)

You are correct. It doesn't work. A function returns a value, but it can't
change an arbitrary cell on the worksheet.
--
Gary''s Student - gsnu200726
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with Range.("XX").Value = (Newbie)

You got your answer why your function won't work.

But I wouldn't name a UDF =sum() since excel has its own =sum() function.



David Andrews wrote:

I have a function that sums 3 values:

********
Public Function sum(UserRange) As Double

sum = 0

For Each cell In UserRange
sum = sum + cell.Value
Next cell

Range("H5").Value = 7 : THIS DOESNT WORK ???

mysum = sum

End Function
******
The call for it is in a cell (G4) , =sum(G1:G3)
I am trying to set the value of another cell in this function using
Range("H5").Value = 7,but it does nothing.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Help with Range.("XX").Value = (Newbie)

thanks for the responses. I wasted alot of time on this..

Can one of you help with the syntax for passing a few different cell values
to a calling function

Cell Call:
=compute(C1,C3,C5)

*****
function compute( ??????)

'get the value of the 3 cells and do a calculation

end function
*****

"David Andrews" wrote in message
news:V%z8i.1968$FU4.119@trndny02...
I have a function that sums 3 values:

********
Public Function sum(UserRange) As Double

sum = 0

For Each cell In UserRange
sum = sum + cell.Value
Next cell

Range("H5").Value = 7 : THIS DOESNT WORK ???


mysum = sum

End Function
******
The call for it is in a cell (G4) , =sum(G1:G3)
I am trying to set the value of another cell in this function using
Range("H5").Value = 7,but it does nothing.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Help with Range.("XX").Value = (Newbie)

Hi David,

Perhaps try something like:

'=============
Public Function SumOfSquares( _
ParamArray myCells()) _
As Double
Dim i As Long, j As Long
Dim var As Variant

For i = LBound(myCells) To UBound(myCells)
If IsArray(myCells(i)) Then
For j = 1 To myCells(i).Count
var = myCells(i)(j)
If IsNumeric(var) Then
SumOfSquares = SumOfSquares + var ^ 2
End If
Next j
Else
SumOfSquares = SumOfSquares + myCells(i) ^ 2
End If
Next i
End Function
'<<=============


---
Regards,
Norman


"David Andrews" wrote in message
news:5RA8i.3810$WE4.2054@trndny01...
thanks for the responses. I wasted alot of time on this..

Can one of you help with the syntax for passing a few different cell
values
to a calling function

Cell Call:
=compute(C1,C3,C5)

*****
function compute( ??????)

'get the value of the 3 cells and do a calculation

end function
*****

"David Andrews" wrote in message
news:V%z8i.1968$FU4.119@trndny02...
I have a function that sums 3 values:

********
Public Function sum(UserRange) As Double

sum = 0

For Each cell In UserRange
sum = sum + cell.Value
Next cell

Range("H5").Value = 7 : THIS DOESNT WORK ???


mysum = sum

End Function
******
The call for it is in a cell (G4) , =sum(G1:G3)
I am trying to set the value of another cell in this function using
Range("H5").Value = 7,but it does nothing.






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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Range("B2").AutoFill Destination:=Range("GX1", ActiveCell) ... Fails but why? [email protected] Excel Programming 0 March 13th 07 02:16 AM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM
Using "Cells" to write "Range("A:A,H:H").Select" Trip Ives[_2_] Excel Programming 3 June 5th 04 03:13 PM


All times are GMT +1. The time now is 05:10 PM.

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

About Us

"It's about Microsoft Excel"