Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to find the Dimensions of a Variant Range

I have a worksheet contains a named range referenced to cells A1:C3 called
InputRange
I read this range into a variant and then want the dimensions of the
variant.

Sub ReadRange()
Dim IRange() As Variant
IRange() = Range("InputRange")
End Sub

I tried but I can only find the vertical dimension with the following:
MsgBox UBound(IRange)
Can someone help me how to find the other dimension?

Thanks a lot on your ideas...

Frans


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to find the Dimensions of a Variant Range

Try

Function GetDims(Arr() As Variant) As Long
Dim Ndx As Long: Ndx = 1
Dim SaveNdx As Long
Dim V As Variant
On Error Resume Next
Do Until Err.Number < 0
V = UBound(Arr, Ndx)
If Err.Number = 0 Then
SaveNdx = Ndx
Else
GetDims = SaveNdx
End If
Ndx = Ndx + 1
Loop
End Function

You can then call this as

Dim Dims As Long
Dims = GetDims(IRange)



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Frans Verhaar" wrote in message
...
I have a worksheet contains a named range referenced to cells
A1:C3 called InputRange
I read this range into a variant and then want the dimensions
of the variant.

Sub ReadRange()
Dim IRange() As Variant
IRange() = Range("InputRange")
End Sub

I tried but I can only find the vertical dimension with the
following: MsgBox UBound(IRange)
Can someone help me how to find the other dimension?

Thanks a lot on your ideas...

Frans



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default How to find the Dimensions of a Variant Range

You should include the LBound as well

MsgBox UBound(IRange, 1) - LBound(IRange,1) + 1

MsgBox UBound(IRange, 2) - LBound(IRange,2) + 1

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Frans Verhaar" wrote in message
...
I have a worksheet contains a named range referenced to cells A1:C3 called
InputRange
I read this range into a variant and then want the dimensions of the
variant.

Sub ReadRange()
Dim IRange() As Variant
IRange() = Range("InputRange")
End Sub

I tried but I can only find the vertical dimension with the following:
MsgBox UBound(IRange)
Can someone help me how to find the other dimension?

Thanks a lot on your ideas...

Frans




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How to find the Dimensions of a Variant Range

Hi,
That works very well. It's quite slim and fast.
Thanks to all of you.

Regards,
Frans

"Bob Phillips" wrote in message
...
You should include the LBound as well

MsgBox UBound(IRange, 1) - LBound(IRange,1) + 1

MsgBox UBound(IRange, 2) - LBound(IRange,2) + 1

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Frans Verhaar" wrote in message
...
I have a worksheet contains a named range referenced to cells A1:C3
called
InputRange
I read this range into a variant and then want the dimensions of the
variant.

Sub ReadRange()
Dim IRange() As Variant
IRange() = Range("InputRange")
End Sub

I tried but I can only find the vertical dimension with the following:
MsgBox UBound(IRange)
Can someone help me how to find the other dimension?

Thanks a lot on your ideas...

Frans






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to find the Dimensions of a Variant Range


Dim lb1&, lb2&, ub1&, ub2&, IRange
lb1 = lbound(IRange,1)
ub1 = Ubound(IRange,1)
lb2 = lbound(IRange,2)
ub2 = Ubound(IRange,2)

--
Regards,
Tom Ogilvy


"Frans Verhaar" wrote:

I have a worksheet contains a named range referenced to cells A1:C3 called
InputRange
I read this range into a variant and then want the dimensions of the
variant.

Sub ReadRange()
Dim IRange() As Variant
IRange() = Range("InputRange")
End Sub

I tried but I can only find the vertical dimension with the following:
MsgBox UBound(IRange)
Can someone help me how to find the other dimension?

Thanks a lot on your ideas...

Frans





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
How do I assign range to variant and use Mike H[_2_] Excel Discussion (Misc queries) 7 June 7th 07 01:40 AM
using find with variant? Don S Excel Programming 4 August 16th 05 04:52 PM
Find Variant StephanieH Excel Programming 7 February 23rd 05 03:48 PM
Changing Properties of a Range object after initial Dimensions ?? Dan Thompson Excel Programming 4 November 3rd 04 05:10 PM
How to define a Range with variant? Yiu Choi Fan Excel Programming 6 July 12th 04 04:41 PM


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