Private Sub UserForm_Initialize()
'********************************************************** CREAZIONE ELENCO LISTA PRESELEZIONE
Application.ScreenUpdating = False
Dim CL As Range, Intervallo As Range, Elenco As New Collection
Dim Valori As Variant
Dim Riga
Set Intervallo = Range("elencotipomezzi")
Set Intervallo = Intervallo.Offset(1, 0).Resize(Intervallo.Rows.Count - 1, Intervallo.Columns.Count)
On Error Resume Next
For Each CL In Intervallo
'**************************************************** scrivo nella collection un indice
Elenco.Add CL.Value, CStr(CL.Value)
Next
On Error GoTo 0
ComboBox1.Clear
For Each Valori In Elenco
ComboBox1.AddItem Valori
Next
Application.ScreenUpdating = True
End Sub
Private Sub Combobox2_Enter()
'********************************************************** POPOLAZIONE ELENCO INSERIMENTO MEZZO
pre = ComboBox1.Text
ric = TextBox2.Text
hmany = Application.WorksheetFunction.CountIf(Range("mezzi"), "*" & pre & "*")
ReDim VArr(hmany)
Riga = Range("mezzi").End(xlDown).Row
For i = 0 To Riga
If Len(Range("mezzi").Cells(i, 1).Text) > Len(Replace(UCase(Range("mezzi").Cells(i, 1).Text), UCase(pre), "")) Then
VArr(j) = Range("mezzi").Cells(i, 1).Text: j = j + 1
End If
Next i
ComboBox2.List = VArr
End Sub
|