Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
BG
 
Posts: n/a
Default Passing Excel NAMED Range to VBA

Given a NAMED range called "Sheet1_Table" that refers to "Sheet1!e1:h4" and
the value "Sheet1_Table" in cell C1, how can I get the following VBA function:

Function say_what(ByRef input_arg As Variant) As Variant
If TypeName(input_arg) = "Range" Then
say_what = input_arg.Rows.Count & " by " & input_arg.Columns.Count
Else
say_what = TypeName(input_arg)
End If
End Function

to return the same result for =say_what( indirect(c1) ) and =say_what( c1 )?

say_what( indirect(c1) ) returns a correct "4 by 4" but say_what( c1 )
returns an incorrect "1 by 1".

Thank you,



How can I get
  #2   Report Post  
Trevor Shuttleworth
 
Posts: n/a
Default

I'd say what the two calls return are correct.

You could also try: =say_what( Sheet1_Table ) = 4 by 4

Regards

Trevor


"BG" wrote in message
...
Given a NAMED range called "Sheet1_Table" that refers to "Sheet1!e1:h4"
and
the value "Sheet1_Table" in cell C1, how can I get the following VBA
function:

Function say_what(ByRef input_arg As Variant) As Variant
If TypeName(input_arg) = "Range" Then
say_what = input_arg.Rows.Count & " by " & input_arg.Columns.Count
Else
say_what = TypeName(input_arg)
End If
End Function

to return the same result for =say_what( indirect(c1) ) and =say_what(
c1 )?

say_what( indirect(c1) ) returns a correct "4 by 4" but say_what( c1 )
returns an incorrect "1 by 1".

Thank you,



How can I get



  #3   Report Post  
BG
 
Posts: n/a
Default

Hi Trevor,

Thank you for your interest!

You are correct - i.e., both calls return results and =say_what(
Sheet1_Table ) returns 4 x 4. However, my question is: How do I make
=say_what( c1 ) produce the same result as =say_what( INDIRECT(c1) )? That
is, what do I need to do in the say_what finction to emulate the INDIRECT
function?

Thanks again, BG

"Trevor Shuttleworth" wrote:

I'd say what the two calls return are correct.

You could also try: =say_what( Sheet1_Table ) = 4 by 4

Regards

Trevor


"BG" wrote in message
...
Given a NAMED range called "Sheet1_Table" that refers to "Sheet1!e1:h4"
and
the value "Sheet1_Table" in cell C1, how can I get the following VBA
function:

Function say_what(ByRef input_arg As Variant) As Variant
If TypeName(input_arg) = "Range" Then
say_what = input_arg.Rows.Count & " by " & input_arg.Columns.Count
Else
say_what = TypeName(input_arg)
End If
End Function

to return the same result for =say_what( indirect(c1) ) and =say_what(
c1 )?

say_what( indirect(c1) ) returns a correct "4 by 4" but say_what( c1 )
returns an incorrect "1 by 1".

Thank you,



How can I get




  #4   Report Post  
Trevor Shuttleworth
 
Posts: n/a
Default

BG

I'm not sure you can do what you want to do. When you pass the function the
range C1 you *are* passing it a 1x1 range, that is one cell. When you pass
it INDIRECT(C1), you are saying "pass the function the range *pointed to* by
the cell C1", in other words, Sheet1_Table ... which is a 4x4 range.

Thought of testing Range(input_arg) but I'm not making any progress. Sorry

Regards

Trevor


"BG" wrote in message
...
Hi Trevor,

Thank you for your interest!

You are correct - i.e., both calls return results and =say_what(
Sheet1_Table ) returns 4 x 4. However, my question is: How do I make
=say_what( c1 ) produce the same result as =say_what( INDIRECT(c1) )?
That
is, what do I need to do in the say_what finction to emulate the INDIRECT
function?

Thanks again, BG

"Trevor Shuttleworth" wrote:

I'd say what the two calls return are correct.

You could also try: =say_what( Sheet1_Table ) = 4 by 4

Regards

Trevor


"BG" wrote in message
...
Given a NAMED range called "Sheet1_Table" that refers to "Sheet1!e1:h4"
and
the value "Sheet1_Table" in cell C1, how can I get the following VBA
function:

Function say_what(ByRef input_arg As Variant) As Variant
If TypeName(input_arg) = "Range" Then
say_what = input_arg.Rows.Count & " by " & input_arg.Columns.Count
Else
say_what = TypeName(input_arg)
End If
End Function

to return the same result for =say_what( indirect(c1) ) and =say_what(
c1 )?

say_what( indirect(c1) ) returns a correct "4 by 4" but say_what( c1 )
returns an incorrect "1 by 1".

Thank you,



How can I get






  #5   Report Post  
BG
 
Posts: n/a
Default

Thank you for your efforts!

"Trevor Shuttleworth" wrote:

BG

I'm not sure you can do what you want to do. When you pass the function the
range C1 you *are* passing it a 1x1 range, that is one cell. When you pass
it INDIRECT(C1), you are saying "pass the function the range *pointed to* by
the cell C1", in other words, Sheet1_Table ... which is a 4x4 range.

Thought of testing Range(input_arg) but I'm not making any progress. Sorry

Regards

Trevor


"BG" wrote in message
...
Hi Trevor,

Thank you for your interest!

You are correct - i.e., both calls return results and =say_what(
Sheet1_Table ) returns 4 x 4. However, my question is: How do I make
=say_what( c1 ) produce the same result as =say_what( INDIRECT(c1) )?
That
is, what do I need to do in the say_what finction to emulate the INDIRECT
function?

Thanks again, BG

"Trevor Shuttleworth" wrote:

I'd say what the two calls return are correct.

You could also try: =say_what( Sheet1_Table ) = 4 by 4

Regards

Trevor


"BG" wrote in message
...
Given a NAMED range called "Sheet1_Table" that refers to "Sheet1!e1:h4"
and
the value "Sheet1_Table" in cell C1, how can I get the following VBA
function:

Function say_what(ByRef input_arg As Variant) As Variant
If TypeName(input_arg) = "Range" Then
say_what = input_arg.Rows.Count & " by " & input_arg.Columns.Count
Else
say_what = TypeName(input_arg)
End If
End Function

to return the same result for =say_what( indirect(c1) ) and =say_what(
c1 )?

say_what( indirect(c1) ) returns a correct "4 by 4" but say_what( c1 )
returns an incorrect "1 by 1".

Thank you,



How can I get






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
In Excel how do I delete or change the name of a range of cells? Naming and Deleting a Range Name Excel Discussion (Misc queries) 4 September 21st 08 11:00 PM
Is there a way to average if in excel when looking at a range of d Aaron Excel Worksheet Functions 1 July 14th 05 08:20 PM
Excel Page Range Printing Problems SkyEyes Excel Discussion (Misc queries) 2 July 11th 05 08:18 PM
combo box named range BB Excel Discussion (Misc queries) 2 June 21st 05 04:27 PM
dynamic range for excel chart bobf Excel Discussion (Misc queries) 1 January 26th 05 11:07 AM


All times are GMT +1. The time now is 07:41 AM.

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"