Sorting a string array in Visual Basic for Applications (VBA) is not as simple as in other, more recent programming languages. In VBA, you can sort an array in ascending order using a couple of "For...Loops" and looping through each element in the array. This method is useful when you need to display values back to the user in ascending order, to give your data a more professional look.
Launch Microsoft Excel, click the "Developer" tab, then click "Visual Basic" to open the VB Editor. Create a new sub procedure by adding the following code:
Private Sub SortVBAArray()
Create your string array and add ten values to it:
Call the sub procedure that will sort the values in the array and end the procedure:
Create the sub procedure that will sort the string array in ascending order and display the results through the Immediate window:
Sub sort Array(tmpArray() As String)
Click the first sub procedure and press "Ctrl" + "G" to display the Immediate window. Press "F5" to run the program and view the results.