I have defined a type as
I then create an array of these entries, and scan a data worksheet to populate the array.
The idea is to then sort the array by lastName, and then populate a listbox with entries that are in alphabetical order by last name.
So in my userform_initialize i populate the array, but when I try to pass it to a sort routine, I get this error
here's a snippet of the code with the relevant lines...the last one is where the error occurs
the bubble sort routine is one I found online and then modified to use the custom type
This is a little outside my normal realm, so I'm not sure how to proceed....any help would be greatly appreciated.
Code:
Public Type entryRecord
firstName As String
lastName As String
amount As String
letterDate As String
End Type
I then create an array of these entries, and scan a data worksheet to populate the array.
The idea is to then sort the array by lastName, and then populate a listbox with entries that are in alphabetical order by last name.
So in my userform_initialize i populate the array, but when I try to pass it to a sort routine, I get this error
Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions
here's a snippet of the code with the relevant lines...the last one is where the error occurs
Code:
Dim entryArray() As entryRecord
Dim sortedArray() As entryRecord
ReDim entryArray(1 To numEntries) 'size the array to the number of entries
ReDim sortedArray(1 To numEntries)
sortedArray = BubbleSrt(entryArray, True)
the bubble sort routine is one I found online and then modified to use the custom type
Code:
Public Function BubbleSrt(ArrayIn, Ascending As Boolean)
Dim SrtTemp As Variant
Dim i As Long
Dim j As Long
If Ascending = True Then
For i = LBound(ArrayIn) To UBound(ArrayIn)
For j = i + 1 To UBound(ArrayIn)
If ArrayIn(i).lastName > ArrayIn(j).lastName Then
SrtTemp = ArrayIn(j)
ArrayIn(j) = ArrayIn(i)
ArrayIn(i) = SrtTemp
End If
Next j
Next i
Else
For i = LBound(ArrayIn) To UBound(ArrayIn)
For j = i + 1 To UBound(ArrayIn)
If ArrayIn(i).lastName < ArrayIn(j).lastName Then
SrtTemp = ArrayIn(j)
ArrayIn(j) = ArrayIn(i)
ArrayIn(i) = SrtTemp
End If
Next j
Next i
End If
BubbleSrt = ArrayIn
End Function
This is a little outside my normal realm, so I'm not sure how to proceed....any help would be greatly appreciated.