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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| Option Explicit
Const FondRouge = &H8080FF
Private Sub CANCEL_Click()
Unload Me
End Sub
Private Sub OK_Click()
End Sub
Private Sub Datel_Change()
If IsDate(Me.Datel) Then
Me.Datel.BackColor = Me.Tarifs.BackColor
Tarifs_Change
Else
Me.Datel.BackColor = FondRouge
End If
End Sub
Private Sub Tarifs_Change()
Dim i As Integer, j As Integer
'feuille contenant la valeur à chercher
With Sheets("tarifs HT")
'de la ligne 2 à la dernière ligne utilisée de la colonne C
For i = 3 To .Cells(Rows.Count, 3).End(xlUp).Row
'recherche de la ligne en colonne A qui correspond à la sélection de la ComboBox
If .Cells(i, 1) = Me.Tarifs Then
'si oui tarifs = colonne suivante même ligne
Me.DroitEntree = .Cells(i, 3)
'de la colonne A à la dernière colonne de la région courante (on balaie la 1ère ligne à la recherche d'une date)
'par défaut, on prend la cotisation colonne 4 ("D")
Me.CotisationAn = .Cells(i, 4)
If IsDate(Me.Datel) Then
For j = 1 To .[a1].CurrentRegion.Columns.Count
'mais si on trouve une date correspondante dans les autres colonnes on écrase la valeur par défaut
If IsDate(.Cells(1, j)) Then
'recherche du tarif selon la date
'on compare la date de début et la date de fin de la période
If CDate(Me.Datel.Value) >= .Cells(1, j) And CDate(Me.Datel.Value) <= .Cells(2, j) Then
CotisationAn = .Cells(i, j)
'on ajoute la cotisation avec le droit d'entrée pour le total
Exit For
End If
End If
Next j
End If
Me.TarifHT = CDec(Me.CotisationAn) + CDec(Me.DroitEntree)
Exit For
End If
Next i
End With
End Sub
Private Sub UserForm_Initialize()
Dim S As Worksheet
Dim R As Range
Dim var As Variant
'--- Monte les données dans la ComboBox ---
Set S = Sheets("tarifs HT")
Set R = S.Range("A3", S.Cells(S.Cells(S.Rows.Count, 1).End(xlUp).Row, 1))
'Set R = S.Range("a3:a" & S.[a65536].End(xlUp).Row)
var = R
Me.Tarifs.List = var
'-------------
Me.Datel = Format(Date, "dd/mm/yyyy")
End Sub |
Partager