Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Ubound(x) gives rows in a range-array - but what about columns ?

Hi experts:

Lets say i got:
ActiveSheet.UsedRange.Select
x = Selection
r=Ubound(x) ' numbers of rows

problem is how do i get columns ?

i tryed
c=x.columns
c=x.columns.count
c=Range(x).columns

nothing works grrrrrr

Help pls. :-)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Ubound(x) gives rows in a range-array - but what about columns ?

One way:

Sub GetRowsAndColums()
Dim x As Range
Dim rRow
Dim cCol

ActiveSheet.UsedRange.Select

Set x = Selection
cCol = x.Columns.Count
rRow = x.Rows.Count

MsgBox rRow & " " & cCol

End Sub

Regards

Trevor


"excelent" wrote in message
...
Hi experts:

Lets say i got:
ActiveSheet.UsedRange.Select
x = Selection
r=Ubound(x) ' numbers of rows

problem is how do i get columns ?

i tryed
c=x.columns
c=x.columns.count
c=Range(x).columns

nothing works grrrrrr

Help pls. :-)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Ubound(x) gives rows in a range-array - but what about columns ?

It is good practice to always declare your variables and
to use the default properties of objects.
'---------------
Sub MNO()
Dim x As Variant
Dim Rw As Long
Dim Col As Long

'Transfer range values as a 2 dimensional array to the variant variable.
x = Selection.Value
Rw = UBound(x, 1)
Col = UBound(x, 2)
MsgBox Rw & " " & Col

'Assigns object reference to the variable.
'This works for a variant or range object variable.
Set x = Selection
Rw = x.Rows.Count
Col = x.Columns.Count
MsgBox Rw & " " & Col
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"excelent"

wrote in message
Hi experts:

Lets say i got:
ActiveSheet.UsedRange.Select
x = Selection
r=Ubound(x) ' numbers of rows

problem is how do i get columns ?

i tryed
c=x.columns
c=x.columns.count
c=Range(x).columns

nothing works grrrrrr
Help pls. :-)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Ubound(x) gives rows in a range-array - but what about columns

ok Trevor ty for reply, ill try that

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Ubound(x) gives rows in a range-array - but what about columns

y ur right bout that Jim ill try to remember :-)
tks for reply, hope i got it now.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Ubound(x) gives rows in a range-array - but what about columns ?

One more working with the array:

Dim x As Variant
x = ActiveSheet.UsedRange.Value
MsgBox UBound(x, 1) & vbLf & UBound(x, 2)

(rows, then columns)

excelent wrote:

Hi experts:

Lets say i got:
ActiveSheet.UsedRange.Select
x = Selection
r=Ubound(x) ' numbers of rows

problem is how do i get columns ?

i tryed
c=x.columns
c=x.columns.count
c=Range(x).columns

nothing works grrrrrr

Help pls. :-)


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 695
Default Ubound(x) gives rows in a range-array - but what about columns

yep works too
tks. Dave

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 name rows and columns in an array Gulfman100 New Users to Excel 1 January 5th 08 01:50 AM
Array Ubound gti_jobert[_71_] Excel Programming 6 March 27th 06 10:34 PM
UBound of multi-dimensional array? Jake Marx[_3_] Excel Programming 0 August 16th 05 06:34 PM
Handling ubound on an uninitialised array Mike NG Excel Programming 14 January 24th 05 09:05 AM


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