答案1
尝试此代码。将其粘贴到 VB 编辑器窗口并运行它(谷歌搜索“如何运行 vba 代码”以获取更多帮助)。这根本不高效,但它应该可以工作。
Sub Some_Sorting_Procedure()
Dim r As Long, last_row As Long
Dim i As Long, j As Long
Dim arr As Variant
Application.ScreenUpdating = False
With ActiveSheet
last_row = .Cells(.Rows.Count, 1).End(xlUp).Row
For r = 2 To last_row
For i = 3 To 23 Step 4
For j = i + 4 To 23 Step 4
If .Cells(r, i).Value > .Cells(r, j).Value Then
arr = .Cells(r, j).Resize(, 4).Value
.Cells(r, i).Resize(, 4).Cut .Cells(r, j)
.Cells(r, i).Resize(, 4).Value = arr
End If
Next j
Next i
Next r
End With
End Sub
编辑
假设您的数据从单元格开始A1
,并且第一列中没有空单元格。硬编码值23
是因为您提到只有六笔交易。对于每笔额外的交易,您需要将此数字增加 4。