How to generalize sorting range in macro???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have recorded a macro which would help me to sort a list of data. First,
when I have done with the recording, I found out that the range of the data
list is being hard coded in the marco, for example, Range("A1:F30").Sort
.......

But what happen is I may have different ranges of lists! Sometimes, the list
may be shorten then the previous one but sometimes may be longer then. So, I
tried to replace the fixed range with a Range Object variable; but it doesn't
work and the system generated a debug!!!

How actually to solve this problem????
Please advise........

Thanking in advance!!
 
If you like Excel to identify the range, then just use a single variable in
the range - preferrable the index range

With Range("D1")
.Sort Key1:=.Cells(1,1), Order1:=xlAscending
End With

or
Dim rng as Range
set rng = Range("A1").CurrentRegion

rng.Sort Key1:=rng(1).Offset(0,3), Order1:=xlAscending
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top