For i = 2 To LastRow ' ソートキーを使ってソート順を決定 For j = i + 1 To LastRow If sortKeys(i) > sortKeys(j) Then Dim tempKey As String ' ソートキーの順序を入れ替え tempKey = sortKeys(i) sortKeys(i) = sortKeys(j) sortKeys(j) = tempKey
Dim tempValue As String ' A列のセルの値も入れ替え tempValue = ws.Cells(i, 1).Value ws.Cells(i, 1).Value = ws.Cells(j, 1).Value ws.Cells(j, 1).Value = tempValue
For k = 2 To 10 ' B列~J列のセルの値も入れ替え tempValue = ws.Cells(i, k).Value ws.Cells(i, k).Value = ws.Cells(j, k).Value ws.Cells(j, k).Value = tempValue Next k End If Next j Next i End Sub