Sub BubbleSort() Dim rowCount As Long Dim colCount As Integer Dim temp As Integer Dim i…
- User
Sub BubbleSort() Dim rowCount As Long Dim colCount As Integer Dim temp As Integer Dim i As Integer, j As Integer
colCount = WorksheetFunction.CountA(Range(“A:A”))
For i = 1 To colCount - 1 For j = 1 To colCount - i + 1 If Cells(j, 1).Value > Cells(j + 1, 1).Value Then temp = Cells(j, 1).Value Cells(j, 1).Value = Cells(j + 1, 1).Value Cells(j + 1, 1).Value = temp
End If
Next j Next i
End Sub
я сделал сортировку пузырьком для столбика с ID в базе данных, сделай так, чтобы во время сортировки вместе с числами ID в столбике A перемещалась и вся строчка
- Assistant
Sub BubbleSort() Dim rowCount As Long Dim colCount As Integer Dim temp As Variant Dim i As Integer, j As Integer
rowCount = Cells(Rows.Count, 1).End(xlUp).Row colCount = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To rowCount - 1 For j = 1 To rowCount - i + 1 If Cells(j, 1).Value > Cells(j + 1, 1).Value Then For k = 1 To colCount temp = Cells(j, k).Value Cells(j, k).Value = Cells(j + 1, k).Value Cells(j + 1, k).Value = temp Next k End If
Next j Next i
End Sub