Please help! I want to put a two dimensional selected range values into a single column array. Then sort the array values in ascending order. Then display the content of the sorted array.
This is VBA and Excel. Thanks!
Sub SortArray()
Dim rangearray() As Variant
Dim SourceRange As Range
Set SourceRange = Selection.CurrentRegion
rangearray = SourceRange.Value
'Call function to sort rangearray
Call Sortarray(rangearray)
End Sub
Sub Sortarray(MyArray() As Variant)
Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As String
Dim list As String
First = LBound(MyArray)
Last = UBound(MyArray)
For i = First To Last - 1
For j = i + 1 To Last
If MyArray(i) > MyArray(j) Then
Temp = MyArray(j)
MyArray(j) = MyArray(i)
MyArray(i) = Temp
End If
Next j
Next i
For i = 1 To UBound(MyArray)
list = list & vbCrLf & MyArray(i)
Next
MsgBox list
End Sub
This is VBA and Excel. Thanks!
Sub SortArray()
Dim rangearray() As Variant
Dim SourceRange As Range
Set SourceRange = Selection.CurrentRegion
rangearray = SourceRange.Value
'Call function to sort rangearray
Call Sortarray(rangearray)
End Sub
Sub Sortarray(MyArray() As Variant)
Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As String
Dim list As String
First = LBound(MyArray)
Last = UBound(MyArray)
For i = First To Last - 1
For j = i + 1 To Last
If MyArray(i) > MyArray(j) Then
Temp = MyArray(j)
MyArray(j) = MyArray(i)
MyArray(i) = Temp
End If
Next j
Next i
For i = 1 To UBound(MyArray)
list = list & vbCrLf & MyArray(i)
Next
MsgBox list
End Sub