PC Review


Reply
Thread Tools Rate Thread

how do I pass myfunction(A2:A4) instead of myfunction("A2:A4")

 
 
Andy B
Guest
Posts: n/a
 
      26th Nov 2008
I want to define a function that takes a range in and operates on that range.
I want to use the normal Excel method of defining the range as (A2:A4), not
as a string. (If I use the string format, excel doesn't recalculate the
function when the data in the range changes)

when I define
function myfunction (inrange as Range) , the function call seems to fail.
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Nov 2008
myfunction( RANGE("A2:A4") )

"Andy B" wrote:

> I want to define a function that takes a range in and operates on that range.
> I want to use the normal Excel method of defining the range as (A2:A4), not
> as a string. (If I use the string format, excel doesn't recalculate the
> function when the data in the range changes)
>
> when I define
> function myfunction (inrange as Range) , the function call seems to fail.

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      26th Nov 2008
Just an added comment. If you use A1 format for a range, it has to be a
string. Using the Cells format the row and column index numbers are numeric
as are the numbers in the R1C1 format. If you were referring to the $A$1
format, The $ symbol in this case indicates absolute reference, as opposed
to relative reference, and not to be confused with when it used as a type
designation character.

"Andy B" wrote:

> I want to define a function that takes a range in and operates on that range.
> I want to use the normal Excel method of defining the range as (A2:A4), not
> as a string. (If I use the string format, excel doesn't recalculate the
> function when the data in the range changes)
>
> when I define
> function myfunction (inrange as Range) , the function call seems to fail.

 
Reply With Quote
 
Andy B
Guest
Posts: n/a
 
      26th Nov 2008
as usual, I wasn't too clear. I want to call the function from an excel cell
in a worksheet. In the same manner that you can use SUM(A1:A100), I want to
do myfunction(A1:A100). I am trying to build a more general concatenate
function - concatenate(A1:A100) -

"JLGWhiz" wrote:

> Just an added comment. If you use A1 format for a range, it has to be a
> string. Using the Cells format the row and column index numbers are numeric
> as are the numbers in the R1C1 format. If you were referring to the $A$1
> format, The $ symbol in this case indicates absolute reference, as opposed
> to relative reference, and not to be confused with when it used as a type
> designation character.
>
> "Andy B" wrote:
>
> > I want to define a function that takes a range in and operates on that range.
> > I want to use the normal Excel method of defining the range as (A2:A4), not
> > as a string. (If I use the string format, excel doesn't recalculate the
> > function when the data in the range changes)
> >
> > when I define
> > function myfunction (inrange as Range) , the function call seems to fail.

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      26th Nov 2008
You could use code similar to the following:

Function Concat(RR As Range) As String
Dim S As String
Dim R As Range
For Each R In RR.Cells
S = S & R.Text
Next R
Concat = S
End Function

Then, call this from a worksheet with

=Concat(A1:A100)

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Wed, 26 Nov 2008 07:16:05 -0800, Andy B
<(E-Mail Removed)> wrote:

>as usual, I wasn't too clear. I want to call the function from an excel cell
>in a worksheet. In the same manner that you can use SUM(A1:A100), I want to
>do myfunction(A1:A100). I am trying to build a more general concatenate
>function - concatenate(A1:A100) -
>
>"JLGWhiz" wrote:
>
>> Just an added comment. If you use A1 format for a range, it has to be a
>> string. Using the Cells format the row and column index numbers are numeric
>> as are the numbers in the R1C1 format. If you were referring to the $A$1
>> format, The $ symbol in this case indicates absolute reference, as opposed
>> to relative reference, and not to be confused with when it used as a type
>> designation character.
>>
>> "Andy B" wrote:
>>
>> > I want to define a function that takes a range in and operates on that range.
>> > I want to use the normal Excel method of defining the range as (A2:A4), not
>> > as a string. (If I use the string format, excel doesn't recalculate the
>> > function when the data in the range changes)
>> >
>> > when I define
>> > function myfunction (inrange as Range) , the function call seems to fail.

 
Reply With Quote
 
egun
Guest
Posts: n/a
 
      26th Nov 2008
This worked for me, assuming this is what you're trying to do. Note that it
only works for a single selection. It should be easily extended to cases
with multiple selections.
'
' Concatenate all the values in the supplied range of
' cells into a text string in the target cell
'
Public Function ConcatenateCells(InputRange As Range) As String
Dim rng As Range
Dim Cel As Range
Dim tStr As String
'
tStr = ""
'
' (below is not needed, just showing how you can
' figure out which cell contains the function call)
'
Set rng = Application.Caller
'
For Each Cel In InputRange.Cells
tStr = tStr & Cel.Text & " "
Next Cel
'
tStr = Trim(tStr)
'
ConcatenateCells = tStr
'
End Function


HTH,

Eric
-------------------------
If toast always lands butter-side down, and cats always land on their feet,
what happen if you strap toast on the back of a cat and drop it?
Steven Wright (1955 - )


"Andy B" wrote:

> as usual, I wasn't too clear. I want to call the function from an excel cell
> in a worksheet. In the same manner that you can use SUM(A1:A100), I want to
> do myfunction(A1:A100). I am trying to build a more general concatenate
> function - concatenate(A1:A100) -
>
> "JLGWhiz" wrote:
>
> > Just an added comment. If you use A1 format for a range, it has to be a
> > string. Using the Cells format the row and column index numbers are numeric
> > as are the numbers in the R1C1 format. If you were referring to the $A$1
> > format, The $ symbol in this case indicates absolute reference, as opposed
> > to relative reference, and not to be confused with when it used as a type
> > designation character.
> >
> > "Andy B" wrote:
> >
> > > I want to define a function that takes a range in and operates on that range.
> > > I want to use the normal Excel method of defining the range as (A2:A4), not
> > > as a string. (If I use the string format, excel doesn't recalculate the
> > > function when the data in the range changes)
> > >
> > > when I define
> > > function myfunction (inrange as Range) , the function call seems to fail.

 
Reply With Quote
 
egun
Guest
Posts: n/a
 
      26th Nov 2008
P.S. - the call in my test worksheet, in cell C1, was
"=concatenatecells(A1:A26)", and concatenated the alphabet into cell C1, with
spaces between each letter.

Eric
 
Reply With Quote
 
Andy B
Guest
Posts: n/a
 
      26th Nov 2008
Thank you.

"Chip Pearson" wrote:

> You could use code similar to the following:
>
> Function Concat(RR As Range) As String
> Dim S As String
> Dim R As Range
> For Each R In RR.Cells
> S = S & R.Text
> Next R
> Concat = S
> End Function
>
> Then, call this from a worksheet with
>
> =Concat(A1:A100)
>
> Cordially,
> Chip Pearson
> Microsoft MVP
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
>
>
> On Wed, 26 Nov 2008 07:16:05 -0800, Andy B
> <(E-Mail Removed)> wrote:
>
> >as usual, I wasn't too clear. I want to call the function from an excel cell
> >in a worksheet. In the same manner that you can use SUM(A1:A100), I want to
> >do myfunction(A1:A100). I am trying to build a more general concatenate
> >function - concatenate(A1:A100) -
> >
> >"JLGWhiz" wrote:
> >
> >> Just an added comment. If you use A1 format for a range, it has to be a
> >> string. Using the Cells format the row and column index numbers are numeric
> >> as are the numbers in the R1C1 format. If you were referring to the $A$1
> >> format, The $ symbol in this case indicates absolute reference, as opposed
> >> to relative reference, and not to be confused with when it used as a type
> >> designation character.
> >>
> >> "Andy B" wrote:
> >>
> >> > I want to define a function that takes a range in and operates on that range.
> >> > I want to use the normal Excel method of defining the range as (A2:A4), not
> >> > as a string. (If I use the string format, excel doesn't recalculate the
> >> > function when the data in the range changes)
> >> >
> >> > when I define
> >> > function myfunction (inrange as Range) , the function call seems to fail.

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
"KARACHI UNIVERSITY Centers of BSc (Pass) 1st/2nd year ComputerScience Practical Examination 2009" "KARACHI UNIVERSITY DATE SHEET B.COM" saima81 Microsoft C# .NET 0 10th Apr 2010 05:56 PM
=IF(AND(B2,D2,F2<1:50),"Fail","Pass") please correct the formula =?Utf-8?B?U2FqaWQ=?= Microsoft Access 4 31st Mar 2005 09:02 PM
ControlSource = MyFunction() Albert Microsoft Access Form Coding 0 15th Sep 2004 06:51 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM
How do I get a query to return a "Pass" or "Fail" on calculated data? MrDangerous Microsoft Access 3 2nd Oct 2003 05:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:18 PM.