Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Dumb newbie Q re. passing cell addresses to a UDF.

I'm still making the transition from Object Pascal, and cells and
other concepts in Excel are throwing me a bit.

I've written a function to which I pass one or more cell addresses,
e.g.:

Function MyFunc(ParamArray SomeCellAddresses()) As SomethingOrOther

It itself gets called from a cell, e.g.:

=MyFunc(A1, C45, B13, etc...)

Inside MyFunc, for each argument passed, I'd like to know BOTH the
cell address that was passed and that cell's contents. As it stands,
Excel seems to pass these arguments as the LATTER, and the cell refs
seem lost.

There isn't something I can do inside MyFunc to have my cake and eat
it too, is there? Namely, additionally retrieve the passed addresses?

Or does Excel indeed do just what I'm observing--convert cell address
arguments to the cell contents before function calls, thereby
requiring me to, say, pass the addresses as strings and use INDIRECT
in MyFunc, instead?

Thanks much.

***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Dumb newbie Q re. passing cell addresses to a UDF.


A function called from a worksheet cell can only return a value to that cell.
It cannot change other cell values and cannot change the physical
characteristics of any cell.
Also, the tips and advice here can help keep answers coming ...
http://www.cpearson.com/excel/newposte.htm
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





wrote in message
I'm still making the transition from Object Pascal, and cells and
other concepts in Excel are throwing me a bit.
I've written a function to which I pass one or more cell addresses,
e.g.:

Function MyFunc(ParamArray SomeCellAddresses()) As SomethingOrOther

It itself gets called from a cell, e.g.:

=MyFunc(A1, C45, B13, etc...)

Inside MyFunc, for each argument passed, I'd like to know BOTH the
cell address that was passed and that cell's contents. As it stands,
Excel seems to pass these arguments as the LATTER, and the cell refs
seem lost.

There isn't something I can do inside MyFunc to have my cake and eat
it too, is there? Namely, additionally retrieve the passed addresses?
Or does Excel indeed do just what I'm observing--convert cell address
arguments to the cell contents before function calls, thereby
requiring me to, say, pass the addresses as strings and use INDIRECT
in MyFunc, instead?
Thanks much.
***
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Dumb newbie Q re. passing cell addresses to a UDF.

This worked for me.

Function MyFunc(ParamArray mycells()) As String
Dim i As Integer, cell As Range
For i = LBound(mycells) To UBound(mycells)
Set cell = mycells(i)
MyFunc = MyFunc & "'" & _
cell.Parent.Name & "'!" & cell.Address(0,0) & _
" has a value of " & cell.Value & ";"
Next
End Function

=myfunc(A1, A2)
=myfunc(Sheet2!A1, A2)

For areas that can consist of one or more cells, I'd modify it, so this does
everything the above one does and mo

Function MyFunc(ParamArray mycells()) As String
Dim i As Integer, cell As Range, rng As Range
For i = LBound(mycells) To UBound(mycells)
Set rng = mycells(i)
For Each cell In rng.cells
MyFunc = MyFunc & "'" & cell.Parent.Name & _
"'!" & cell.Address(0, 0) & _
" has a value of " & cell.Value & ";"
Next
Next
End Function

=myfunc(A1:A2, Z1:Z3, Sheet2!A5:A7)
=myfunc(A1, A2)


--
Tim Zych
SF, CA

wrote in message
...
I'm still making the transition from Object Pascal, and cells and
other concepts in Excel are throwing me a bit.

I've written a function to which I pass one or more cell addresses,
e.g.:

Function MyFunc(ParamArray SomeCellAddresses()) As SomethingOrOther

It itself gets called from a cell, e.g.:

=MyFunc(A1, C45, B13, etc...)

Inside MyFunc, for each argument passed, I'd like to know BOTH the
cell address that was passed and that cell's contents. As it stands,
Excel seems to pass these arguments as the LATTER, and the cell refs
seem lost.

There isn't something I can do inside MyFunc to have my cake and eat
it too, is there? Namely, additionally retrieve the passed addresses?

Or does Excel indeed do just what I'm observing--convert cell address
arguments to the cell contents before function calls, thereby
requiring me to, say, pass the addresses as strings and use INDIRECT
in MyFunc, instead?

Thanks much.

***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Dumb newbie Q re. passing cell addresses to a UDF.

Jim & Tim:

Thanks VERY much for replying.

I'll try both suggestions.

***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Dumb newbie Q re. passing cell addresses to a UDF.

P.S.:

It turns out that my problem was that I was not using syntax "Set".

In copying each value of ParamArray to a Range var, I was merely using
"=", and execution simply went into limbo on that line.

"Set" makes it work.

Thanks again.

***
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
Help! Probably dumb newbie question but need help with if/then?? excel-idiot New Users to Excel 1 July 12th 08 05:16 AM
*Dumb newbie* How to automatically import data from 1 workbork to another Hosh New Users to Excel 3 May 9th 07 05:45 PM
Passing Addresses Instead of Values John Excel Programming 1 December 2nd 06 11:15 AM
total dumb newbie question ayla Excel Discussion (Misc queries) 1 November 30th 05 03:57 PM
Newbie stuck on Passing a Variable into a Range Dave Baranas Excel Programming 0 August 13th 03 07:54 AM


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