How can I sort contents of one column based on the contents ofanother column?

  • Thread starter Thread starter yajiv.vijay
  • Start date Start date
Y

yajiv.vijay

I have some data in column "A" and random numeric values in column
"B".
I want to sort column "A" based on the ascending order of column "B".
I was able to do it manually by selecting both the columns and
sorting. But i dont know how to do it in a macro...
 
hi
Dim r As Range
Set r = Range("A1", Range("A1").End(xlDown).Offset(0, 1))

r.Sort Key1:=Range("B1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

when ever you hit a syntax snag, do what i do. turn on the recorder and
perform the desired actions manually. most of the time, the recorder will
show you the basic syntax and give you a basic idea of how to code it.
sometimes editing is reguired but you do get the basic idea. very helpful for
people just starting out.

Regards
FSt1
 
Back
Top