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. :-) |
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. :-) |
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. :-) |
Ubound(x) gives rows in a range-array - but what about columns
ok Trevor ty for reply, ill try that
|
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. |
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 |
Ubound(x) gives rows in a range-array - but what about columns
yep works too
tks. Dave |
All times are GMT +1. The time now is 11:51 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com