Sort two columns Excel [closed]

2019-08-17 09:35发布

I have two different columns on Excel. I want to create a script that will sort Column F, (Have a header) and will sort Column B based on where Column F's sort worked out. (Without affecting any other columns however!)

So if I have

    ColB       ColF
 1. Cat        2
 2. Mouse      1
 3. Dog        3

The sort will give me

    ColB       ColF
 1. Mouse        1
 2. Cat          2
 3. Dog          3

How can I do this? I tried recording a macro of just sorting it out, but I get an error saying "The command cannot be performed with multiple selections, Click a single range and try again"

1条回答
女痞
2楼-- · 2019-08-17 09:43

The easiest way I can think of is to temporarily copy over your two columns into a vertical look-up table with column F on the left.

Then sort your column F and update column D with VLookup with the format like:

=VLOOKUP(F1,[Temp Table Range],2,FALSE)

Then if you want to delete the temp table, just make sure you replace column D's formulas with values.

You can do all of this with a macro it just has several steps. I could write it for you, but that isn't really what Stackoverflow is about.

Have fun. :-)

查看更多
登录 后发表回答