![排序行:6 個交易,其中日期和操作資訊分組在一起](https://rvso.com/image/1597820/%E6%8E%92%E5%BA%8F%E8%A1%8C%EF%BC%9A6%20%E5%80%8B%E4%BA%A4%E6%98%93%EF%BC%8C%E5%85%B6%E4%B8%AD%E6%97%A5%E6%9C%9F%E5%92%8C%E6%93%8D%E4%BD%9C%E8%B3%87%E8%A8%8A%E5%88%86%E7%B5%84%E5%9C%A8%E4%B8%80%E8%B5%B7.png)
答案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
編輯
這假設您的資料從 cell 開始A1
,且第一列中沒有空白儲存格。硬編碼值23
是因為您提到只有六筆交易。對於每筆額外的交易,您都需要將該數字增加 4。