在Excel中按另一个列表的顺序对范围进行sorting

我有两张桌子,像这样:

表格1

  一个
 1第一阶段
 2 SecondPhase
 3第三阶段
 4第四阶段

表2

   AB
 1 Item1 FirstPhase
 2项目4第四阶段
 3 Item2 SecondPhase
 4 Item3 ThirdPhase

我想在sorting后得到的结果是:

   AB
 1 Item1 FirstPhase
 2 Item2 SecondPhase
 3 Item3 ThirdPhase
 4项目4第四阶段

如何按照第一个表中列A的顺序,按列B对第二个表进行sorting?

第一步是创build一个自定义列表。

  • 在Excel 2007中,单击Office图标
  • selectExcel选项 – 热门 – 编辑自定义列表
  • 点击“从单元格导入列表”范围button
  • select您的数据,然后按Enter键
  • 点击导入button
  • 点击确定,然后再次确定

用自定义列表sorting

  • select要sorting的数据。
  • 点击主页选项卡和sorting和filter
  • select自定义sorting
  • select要sorting的列
  • 然后在订单上下拉并select自定义列表
  • select您的自定义列表
  • 点击确定,然后再次确定

在代码中

 Sub MakeCustomListAndSort() Application.AddCustomList ListArray:=Sheets("Sheet1").Range("A1:A4"), ByRow:=True 'Create the custom list ActiveWorkbook.Worksheets("Sheet2").Range("A1:B4").Sort Key1:=Range("B1:B4"), _ Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=Application.CustomListCount + 1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal 'Sort with latest custom list Application.DeleteCustomList Application.CustomListCount 'Delete the latest custom list End Sub