Question: I want to create a vba code that bubble sorts sorts a 2d excell spreadsheet consisting of a 20 row by 10 column array. I
I want to create a vba code that bubble sorts sorts a 2d excell spreadsheet consisting of a 20 row by 10 column array. I have attached a image of my code for a 1D array bubble sort. I just have trouble applying this to 2 dimensions

Vbubblesort Sub bubblesort() Dim temp As Double Dim i As Integer Dim k As Integer Dim rowsnumb As Integer For k 1 To rowsnumb- 1 Do Until i = rowsnumb-k + 1 If ActiveSheet.Cells (i, 1) .Value > ActiveSheet.Cells (i +1, 1).Value Then temp ActiveSheet.Cells (i, 1). Value Activesheet.Cells (i, 1).Value ActiveSheet.Cells(i ActiveSheet.Cells (i + 1, 1) .Value temp 1, 1).Value End If Loop Next End Sub Vbubblesort Sub bubblesort() Dim temp As Double Dim i As Integer Dim k As Integer Dim rowsnumb As Integer For k 1 To rowsnumb- 1 Do Until i = rowsnumb-k + 1 If ActiveSheet.Cells (i, 1) .Value > ActiveSheet.Cells (i +1, 1).Value Then temp ActiveSheet.Cells (i, 1). Value Activesheet.Cells (i, 1).Value ActiveSheet.Cells(i ActiveSheet.Cells (i + 1, 1) .Value temp 1, 1).Value End If Loop Next End Sub
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
