pour la culture générale!
Bonjour,
histoire de vérifier qu'il est plus rapide d’initialiser les combobox directement avec un plage de cellules!
Code:
1 2 3 4 5 6
| Private Sub UserForm_Initialize()
With Range("A1").CurrentRegion
Me.ComboBox1.List = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1)).Value
Me.ComboBox2.List = Application.Transpose(.Range(.Cells(1, 2), .Cells(1, .Columns.Count)).Value)
End With
End Sub |
la proposition de Pierre recherchait la cellule ce trouvant à l'intersection des valeur de deux combo, mais le deux ListIndex permettent de trouver les coordonnés GPS de la cellule avec précision!
Code:
1 2 3
| Sub Change()
If Me.ComboBox1.ListIndex > -1 And Me.ComboBox2.ListIndex > -1 Then MsgBox Range("B2").Offset(Me.ComboBox1.ListIndex, Me.ComboBox2.ListIndex)
End Sub |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Private Sub UserForm_Initialize()
With Range("A1").CurrentRegion
Me.ComboBox1.List = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1)).Value
Me.ComboBox2.List = Application.Transpose(.Range(.Cells(1, 2), .Cells(1, .Columns.Count)).Value)
End With
End Sub
Private Sub ComboBox1_Change()
Change
End Sub
Private Sub ComboBox2_Change()
Change
End Sub
Sub Change()
If Me.ComboBox1.ListIndex > -1 And Me.ComboBox2.ListIndex > -1 Then MsgBox Range("B2").Offset(Me.ComboBox1.ListIndex, Me.ComboBox2.ListIndex)
End Sub |