Option Explicit
Private sh As Worksheet
Private Sub ListBox1_Click()
Range("C1").Value = UserForm1.ListBox1.Value
End Sub
Private Sub TextBox1_Change()
Call mCaricaListBox("CommandButton")
End Sub
Private Sub UserForm_Initialize()
Set sh = ThisWorkbook.Worksheets("Foglio1")
Call mCaricaListBox("Initialize")
End Sub
Private Sub mCaricaListBox(ByVal s As String)
Dim lRiga As Long
Dim lng As Long
With sh
lRiga = .Range("A" & .Rows.Count).End(xlUp).Row
End With
With Me.ListBox1
If s = "Initialize" Then
For lng = 1 To lRiga
.AddItem (sh.Range("A" & lng).Value)
Next
ElseIf s = "CommandButton" Then
.Clear
For lng = 1 To lRiga
If InStr(sh.Range("A" & lng).Value, Me.TextBox1.Text) Then
.AddItem sh.Range("A" & lng).Value
End If
Next
End If
End With
End Sub
Private Sub UserForm_Terminate()
Set sh = Nothing
End Sub
|