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

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...
 
F

FSt1

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
 

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

Top