Philcjr
03-06-2006, 12:05 PM
I know I am close...but what am I missing?
This code is to sort names that are in a row:
'=========================================
Private Sub UserNameSorter()
Dim ws As Worksheet
Dim vTempName As Variant, vMemory As Variant
Dim Y As Long, Z As Long, First As Long, Last As Long, LastCol As Long
Set ws = ThisWorkbook.Sheets("Data")
LastCol = ws.Cells(4, ws.Columns.Count).End(xlToLeft).Column
'Populates the array with the values from the row
With ws
vMemory = .Range(.Cells(4, 2), .Cells(4, LastCol))
End With
'Defines the first and last values in the array
First = LBound(vMemory, 2)
Last = UBound(vMemory, 2)
For Y = First To Last
For Z = Y + 1 To Last
'Compares the values and swaps if need be
If vMemory(1, Y) > vMemory(1, Z) Then
vTempName = vMemory(1, Y)
vMemory(1, Z) = vMemory(1, Y)
vMemory(1, Y) = vTempName
End If
Next Z
Next Y
'Populates the pulldown with the sorted values
For Y = First To Last
UsernamePwd.AddItem vMemory(1, Y)
Next Y
End Sub
The end result is that it keeps duplicating names.
Thanks,
Phil
This code is to sort names that are in a row:
'=========================================
Private Sub UserNameSorter()
Dim ws As Worksheet
Dim vTempName As Variant, vMemory As Variant
Dim Y As Long, Z As Long, First As Long, Last As Long, LastCol As Long
Set ws = ThisWorkbook.Sheets("Data")
LastCol = ws.Cells(4, ws.Columns.Count).End(xlToLeft).Column
'Populates the array with the values from the row
With ws
vMemory = .Range(.Cells(4, 2), .Cells(4, LastCol))
End With
'Defines the first and last values in the array
First = LBound(vMemory, 2)
Last = UBound(vMemory, 2)
For Y = First To Last
For Z = Y + 1 To Last
'Compares the values and swaps if need be
If vMemory(1, Y) > vMemory(1, Z) Then
vTempName = vMemory(1, Y)
vMemory(1, Z) = vMemory(1, Y)
vMemory(1, Y) = vTempName
End If
Next Z
Next Y
'Populates the pulldown with the sorted values
For Y = First To Last
UsernamePwd.AddItem vMemory(1, Y)
Next Y
End Sub
The end result is that it keeps duplicating names.
Thanks,
Phil