
Option Explicit
Private sh As Worksheet
Private colMarca As Collection
Private colMod As Collection
Private lRiga As Long
Private Sub UserForm_Initialize()
Dim lng As Long
Set colMarca = New Collection
Set sh = ThisWorkbook.Worksheets("Foglio2")
With sh
lRiga = .Range("A" & .Rows.Count).End(xlUp).Row
For lng = 2 To lRiga
On Error Resume Next
colMarca.Add CStr(.Cells(lng, 1).Value), CStr(.Cells(lng, 1).Value)
If Err.Number = 0 Then
Me.ComboBox1.AddItem (.Cells(lng, 1).Value)
End If
Err.Number = 0
Next
End With
End Sub
Private Sub ComboBox1_Click()
Dim lng As Long
Set colMod = New Collection
Set sh = ThisWorkbook.Worksheets("Foglio2")
With sh
lRiga = .Range("B" & .Rows.Count).End(xlUp).Row
For lng = 2 To lRiga
On Error Resume Next
colMod.Add CStr(.Cells(lng, 2).Value), CStr(.Cells(lng, 2).Value)
If Err.Number = 0 Then
Me.ComboBox2.AddItem (.Cells(lng, 2).Value)
End If
Err.Number = 0
Next
End With
End Sub
Private Sub UserForm_Terminate()
Set colMarca = Nothing
Set colMod = Nothing
Set sh = Nothing
End Sub
|
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Private sh As Worksheet
Private colMarca As Collection
Private colMod As Collection
Private lRiga As Long
Private Sub ComboBox1_Change()
Dim lng As Long
'Me.ComboBox2.Clear
Set colMod = New Collection
Set sh = ThisWorkbook.Worksheets("Foglio2")
Me.ComboBox2.Clear
With sh
lRiga = .Range("B" & .Rows.Count).End(xlUp).Row
On Error Resume Next
For lng = 2 To lRiga
If .Cells(lng, 1).Value = Me.ComboBox1.Value Then
colMod.Add CStr(.Cells(lng, 2).Value), CStr(.Cells(lng, 2).Value)
If Err.Number = 0 Then
Me.ComboBox2.AddItem (.Cells(lng, 2).Value)
End If
Err.Clear
End If
Next
End With
Set colMod = Nothing
Set sh = Nothing
End Sub
Private Sub UserForm_Initialize()
Dim lng As Long
Set colMarca = New Collection
Set sh = ThisWorkbook.Worksheets("Foglio2")
With sh
lRiga = .Range("A" & .Rows.Count).End(xlUp).Row
On Error Resume Next
For lng = 2 To lRiga
colMarca.Add CStr(.Cells(lng, 1).Value), CStr(.Cells(lng, 1).Value)
If Err.Number = 0 Then
Me.ComboBox1.AddItem (.Cells(lng, 1).Value)
End If
Err.Clear
Next
End With
Set colMarca = Nothing
Set sh = Nothing
End Sub
Private Sub UserForm_Terminate()
Set colMarca = Nothing
Set colMod = Nothing
Set sh = Nothing
End Sub
|
