Forum Discussion
Chyma
Jul 11, 2021Copper Contributor
VBA algorithm for sorting
Hello, I need help with my task in the school, I should write my own bubble for sorting in alphabetic order and not use build-in functions. I know how to do it for numbers but I have no idea how to d...
HansVogelaar
Jul 11, 2021MVP
The bubble sort algorithm for text values is exactly the same as that for numeric values. The only difference is the data type of the variable that you use to store a value temporarily while swapping two values. That variable should be of type String instead of Long (or Double, or whatever you were using).
- anupambit1797Feb 06, 2024Iron Contributor
HiHansVogelaar , how can we check the Performance of different sorting algo using Excel?
Thanks in Advance,
Br,
Anupam
- HansVogelaarFeb 06, 2024MVP
Use code like this:
Sub TestBubbleSort() Dim t As Single ' to keep track of time Dim MyArray ' Array to be sorted ' Set up MyArray ' ... t = Timer Call BubbleSort(MyArray) t = Timer - t Debug.Print "Bubble Sort took " & t & " seconds" End Sub
Create similar macros for other sorting algorithms that you want to test: insert sort, heap sort, comb sort, quick sort, ...