我正在尝试将A-Z排序为一系列不按顺序排列的细胞。 3个细胞范围如下
B5:C31
F5:G31
J5:K31
有什么想法吗?
示例:
答案 0 :(得分:0)
您可以使用宏:
Dim i As Integer
Dim Fg As String
Dim ee As Integer
Dim Dime(1 To 3) As Integer
Fg = ActiveSheet.Name
Sheets.Add
ActiveSheet.Name = "Tmp"
ee = 1
For i = 1 To 3
Sheets(Fg).Select
ActiveSheet.Range("Col" & i & "Ran").Copy
Dime(i) = Range("Col" & i & "Ran").Rows.Count
Sheets("Tmp").Select
ActiveSheet.Paste
ee = ee + Dime(i)
ActiveSheet.Range("A" & ee).Select
Sheets(Fg).Select
Next
Sheets("Tmp").Select
ActiveSheet.Range("A1").Select
ActiveWorkbook.Worksheets("Tmp").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Tmp").Sort
.SetRange Range("A1:B" & ee)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ee = 1
For i = 1 To 3
Sheets("Tmp").Select
ActiveSheet.Range("A" & ee & ":B" & (ee + Dime(i) - 1)).Copy
Sheets(Fg).Select
ActiveSheet.Range("Col" & i & "Ran").Select
ActiveSheet.Paste
ee = ee + Dime(i)
Next
Sheets("Tmp").Delete
将所有列(名为Col1Ran,Col2Ran,Col3Ran的范围)复制到临时表中 - >排序 - >重建...
您需要调整代码到您的列...样本使用2列。