如何用excel对每一行进行sorting?

我有一个像这样的excel文件

ABC 1| A_xxxx | B_xxxx | C_xxxx 2| B_xxxx | A_xxxx | C_xxxx 3| C_xxxx | B_xxxx | A_xxxx 

…..(每个xxxx是不同的数字)

我想sorting每一行,使表如下:

  ABC 1| A_xxxx | B_xxxx | C_xxxx 2| A_xxxx | B_xxxx | C_xxxx 3| A_xxxx | B_xxxx | C_xxxx 

….

我怎样才能做到这一点?

这个子将用VBA做到这一点:

 Sub SortValsToCols() Dim w1 As Worksheet Dim w2 As Worksheet Dim rCell As Range Dim rRng As Range Dim rowCounters As New Scripting.Dictionary Dim i As Long Set w1 = Sheets("Sheet1") 'Change to name of the worksheet containing data. Set w2 = Sheets("Sheet2") 'Change to name of a blank worksheet. The sorted data will end up here. Set rRng = w1.Range("A1:C3") 'Change to range of cells containing data. 'Turn off ScreenUpdating to speed up execution. Application.ScreenUpdating = False 'Fills a dictionary with keys from AZ and gives each an initial value of 1. For i = 65 To 90 rowCounters.Add Key:=Chr(i), Item:=1 Next i 'Loops thru all cells in range specified and adds the value after the last populated _ cell in the relevant column to the target sheet. For Each rCell In rRng.Cells w2.Range(Left$(rCell.Value, 1) & rowCounters(Left$(rCell.Value, 1))).FormulaR1C1 = rCell.Value rowCounters(Left$(rCell.Value, 1)) = rowCounters(Left$(rCell.Value, 1)) + 1 Next rCell 'Turn ScreenUpdating back on. Application.ScreenUpdating = True End Sub 

您需要更改3个SET语句以适合您的工作簿,并在运行之前通过VBE中的Tools-> References添加“Microsoft Scripting Runtime”。

还假定所有的单元格值都以?_开始? 是来自AZ的单个大写字母。