Hi,
I've copied and tried the following code and it keeps looping around the
'mainloop' when I step through and check the 'local's window. It seems to run in Excel 2010 in the video I'm watching but I can't determine what's wrong when I run it in Excel 2007. One error I got was 'For without Next' - after 'For mainloop = 0 To UBound(names)' - but even though I input 'Next mainloop', it still doesn't run correctly.
Where is it going wrong?
__________________________________________________________
Sub sortnames()
Dim names(4) As String
Dim mainloop As Integer
Dim compareloop As Integer
Dim temp As String
names(0) = "bob"
names(1) = "BoB"
names(2) = "JOe"
names(3) = "Sally"
names(4) = "fRED"
For mainloop = 0 To UBound(names)
Next
For compareloop = mainloop To UBound(names)
If UCase(names(mainloop)) < UCase(names(compareloop)) Then
temp = names(mainloop)
names(mainloop) = names(compareloop)
names(compareloop) = temp
End If
Next compareloop
End Sub
________________________________________________
Thanks
I've copied and tried the following code and it keeps looping around the
'mainloop' when I step through and check the 'local's window. It seems to run in Excel 2010 in the video I'm watching but I can't determine what's wrong when I run it in Excel 2007. One error I got was 'For without Next' - after 'For mainloop = 0 To UBound(names)' - but even though I input 'Next mainloop', it still doesn't run correctly.
Where is it going wrong?
__________________________________________________________
Sub sortnames()
Dim names(4) As String
Dim mainloop As Integer
Dim compareloop As Integer
Dim temp As String
names(0) = "bob"
names(1) = "BoB"
names(2) = "JOe"
names(3) = "Sally"
names(4) = "fRED"
For mainloop = 0 To UBound(names)
Next
For compareloop = mainloop To UBound(names)
If UCase(names(mainloop)) < UCase(names(compareloop)) Then
temp = names(mainloop)
names(mainloop) = names(compareloop)
names(compareloop) = temp
End If
Next compareloop
End Sub
________________________________________________
Thanks