Table to sort via VBA but row&column size variable!
Hi Bob,
Yes...it worked like a charm. Here is the code I call:
'-------------------
Sub Sort_it()
' Bobs
Dim rng As Range
With ActiveSheet
cLastRow = Cells(Rows.Count, "B").End(xlUp).Row
cLastCol = Cells(5, Columns.Count).End(xlToLeft).Column
Set rng = Range("B5", Cells(cLastRow, cLastCol))
rng.Sort Key1:=Range("C6"), Order1:=xlDescending
End With
End Sub
'---------------
Regards
J_J
"Bob Phillips" wrote in message
...
I hope that you caught the missing ) in
Set rng = Range("B5",Cells(cLastRow,cLastCol)
which should be
Set rng = Range("B5",Cells(cLastRow,cLastCol))
--
HTH
Bob Phillips
"J_J" wrote in message
...
Thank you Bob,
I wish I could finish the rest of the code...:)
J_J
"Bob Phillips" wrote in message
...
cLastRow = Cells(Rows.Count,"B").End(xlUp).Row
cLastCol = Cells(5,Columns.Count).End(xlToLeft).Column
Set rng = Range("B5",Cells(cLastRow,cLastCol)
rng.Sort etc.
--
HTH
RP
(remove nothere from the email address if mailing direct)
"J_J" wrote in message
...
Hi,
I have a table in the region "B5:F130" where the cells B5, C5, D5, E5,
F5
represents the Data Labels and the rest downwords the data. I want to
sort
this table with referece to the numeric data in column B (which are in
region "B6:B130") with VBA coding. The problem is that, although the
starting cell of this table is stable, but the number of rows and
columns
of
this table may change. So the table may reside in B5:H140 or B5:
J150....etc
in the future. Thus I need to use an expression in the code so that
sorting
of this table can be done whatever the row & column size is (of course
not
exceeding excel limitations).
Can anyone suggest a code that will do that please?
Thank you in advance
J_J
|