1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Private Sub ComboBox1_Change()
Dim F As Worksheet
Dim F1 As Worksheet
Dim Ligne As Integer
Set F = Sheets("loyers")
Set F1 = Sheets("Données")
Dim plageLoc As Range
Set plageLoc = F1.Range("A3:D" & F1.Range("A65536").End(xlUp).Row)
X = ComboBox1.Value
On Error Resume Next
TextBox1.Value = Application.WorksheetFunction.VLookup(X, plageLoc, 2, 0)
TextBox2.Value = Application.WorksheetFunction.VLookup(X, plageLoc, 3, 0)
TextBox3.Value = Application.WorksheetFunction.VLookup(X, plageLoc, 4, 0)
End Sub
Private Sub CommandButton1_Click()
Dim F As Worksheet
Dim F1 As Worksheet
Dim plage As Range
Dim Ligne As Integer
Set F = Sheets("loyers")
Set F1 = Sheets("Données")
If ComboBox1.Value = F.Range("A5") Then Set plage = F.Range("A5:A17"): Max = 17
If ComboBox1.Value = F.Range("A20") Then Set plage = F.Range("A20:A32"): Max = 32
If ComboBox1.Value = F.Range("A35") Then Set plage = F.Range("A35:A47"): Max = 47
Ligne = plage.Find("*", , , , xlByColumns, xlPrevious).Row + 1
If Ligne <= Max Then
F.Cells(Ligne, 1) = CDbl(TextBox1.Value)
F.Cells(Ligne, 2) = CDbl(TextBox2.Value)
F.Cells(Ligne, 3) = CDbl(TextBox3.Value)
Else
MsgBox ("Tous les mois remplis pour ce monsieur")
Exit Sub
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim I As Long
For I = 3 To Sheets("Données").Range("A65536").End(xlUp).Row
ComboBox1 = Sheets("Données").Range("A" & I)
If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem Sheets("Données").Range("A" & I)
Next I
ComboBox1.Value = ""
End Sub |
Partager