Reputation: 49
I've written the function displayed below. It works when I use it in the Sub. This is the first time that I'm trying to write a function. I know this is a noob question however I can't seem to get the function to run. It's probably something about not calling the function correctly or maybe not defining the variables in the function header correctly
Can anyone please point me in the right direction.
Function SortArray(ArrayToSort As String)
Dim x As Long, y As Long
Dim TempTxt1 As String
Dim TempTxt2 As String
For x = LBound(ArrayToSort) To UBound(ArrayToSort)
For y = x To UBound(ArrayToSort)
If UCase(ArrayToSort(y)) < UCase(ArrayToSort(x)) Then
TempTxt1 = ArrayToSort(x)
TempTxt2 = ArrayToSort(y)
ArrayToSort(x) = TempTxt2
ArrayToSort(y) = TempTxt1
End If
Next y
Next x
End Function
Sub CreateUniquesList()
Dim References() As String
...
SortArray (References)
...
End Sub
Upvotes: 1
Views: 3396
Reputation: 3324
Add parentheses to make sure the parameter is an array
Function SortArray(ArrayToSort() As String)
'your code
End Function
Sub CreateUniquesList()
Dim References() As String
'...
SortArray References 'lose the parentheses
'...
End Sub
Upvotes: 3