Leandroarb
Board Regular
- Joined
- Oct 7, 2014
- Messages
- 157
I'm adding values to a combobox with a loop, it analyzes numerical values that are in ascending order, but when I open combobox the values are out of order, what could be happening?
I'm used this code:
Explanation: There are repeated values in the range that the loop traverses, so I made the code this way so that only unique values were added.
I'm used this code:
VBA Code:
Private Sub ComboBox1_Enter()
Dim rngCad As Range
Dim c As Range
Dim strArray As String
Dim ArrayCombo As Variant
Set rngCad = Range(Cells(2, 1), Cells(Application.WorksheetFunction.CountA(Sheets("Cadastro").Range("A:A")), 1))
Me.ComboBox1.Clear
For Each c In rngCad
If Application.WorksheetFunction.CountIf(rngCad, c) > 0 And InStr(strArray, c) = 0 Then
ComboBox1.AddItem c
strArray = strArray & c & ", "
Else
strArray = strArray
End If
Next
End Sub
Explanation: There are repeated values in the range that the loop traverses, so I made the code this way so that only unique values were added.