gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
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
codecolCount = WorksheetFunction.CountA(Range("A2:A" & (Cells(Rows.count, "A").End(xlUp).Row) + 1)) For i = 1 To colCount - 1 For j = 1 To colCount - i 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 iEnd Sub последний непустой элемент в столбике никак не затрагивается в сортировке, и ячейка A1 по прежнему участвует в сортировке, когда в ней должн быть название столбика. Исправь это
- Assistant
Sub BubbleSort() Dim rowCount As Long Dim colCount As Integer Dim temp As Integer Dim i As Integer, j As Integer
codecolCount = WorksheetFunction.CountA(Range("A2:A" & (Cells(Rows.count, "A").End(xlUp).Row) + 1)) 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 iEnd Sub