Bonsoir,
j'ai un problème avec une macro... Mon but est de créer deux variables qui pourront changer de valeur en fonction de la valeur d'une colonne. Ces variables seront intégrées dans un SelectCase qui comprend d'autres variables. Cette macro marche sans la partie avec X et Y en fait et je ne comprend pas ce qui ne marche pas. Je vous mets le code que j'ai fait. Je peux vous joindre un fichier Excel exemple si besoin.
Merci d'avance pour vos suggestions!
j'ai un problème avec une macro... Mon but est de créer deux variables qui pourront changer de valeur en fonction de la valeur d'une colonne. Ces variables seront intégrées dans un SelectCase qui comprend d'autres variables. Cette macro marche sans la partie avec X et Y en fait et je ne comprend pas ce qui ne marche pas. Je vous mets le code que j'ai fait. Je peux vous joindre un fichier Excel exemple si besoin.
Sub Réalisation_opération()
Dim i As Long
Dim LigDep As Long
Dim Nb_Lignes As Long
Dim Nb_Lignes1 As Long
Dim Nb_Lignes2 As Long
Dim Nb_Lignes3 As Long
Dim X As Long
Dim Y As Long
Dim varValH As Variant
Dim varValLG As Variant
' Ligne de départ et nombre de lignes à traiter
LigDep = 7
Nb_Lignes = 500
' Dernières lignes de chaque colonne
Nb_Lignes1 = Range("G" & Cells.Rows.Count).End(xlUp).Row
Nb_Lignes2 = Range("H" & Cells.Rows.Count).End(xlUp).Row ' Non utilisé ?
Nb_Lignes3 = Range("J" & Cells.Rows.Count).End(xlUp).Row ' Non utilisé ?
' Effacer le contenu de la colonne N à partir de la ligne 18
If Nb_Lignes1 >= LigDep Then Range("J" & LigDep & ":J" & Nb_Lignes1).ClearContents
' A partir de la ligne 18 jusqu'à la dernière
For i = LigDep To Nb_Lignes
' Vérifier que le contenu des cellules soient numériques
varValH = 0
If IsDate(Range("H" & i).Value) Then varValH = Range("H" & i).Value
varValG = 0
If IsDate(Range("G" & i).Value) Then varValG = Range("G" & i).Value
' Initialiser le fond de couleur de la cellule L
Range("J" & i).Interior.ColorIndex = xlNone
Range("J" & i).Font.ColorIndex = 1
If Range("F" & i).Value = "Hebdomadaire" Then Y = 2 And X = 7
If Range("F" & i).Value = "Bimensuel" Then Y = 4 And X = 15
If Range("F" & i).Value = "Mensuel" Then Y = 6 And X = 20
If Range("F" & i).Value = "Trimestriel" Then Y = 6 And X = 20
If Range("F" & i).Value = "Quadrimestriel" Then Y = 8 And X = 20
If Range("F" & i).Value = "Semestriel" Then Y = 8 And X = 40
If Range("F" & i).Value = "Annuel" Then Y = 10 And X = 45
If Range("F" & i).Value = "Biennal" Then Y = 10 And X = 45
If Range("F" & i).Value = "Quinquénal" Then Y = 10 And X = 45
Select Case varValH - varValG
Case -Y To Y
Range("J" & i).Value = "Dans les temps"
Range("J" & i).Interior.ColorIndex = 27
Case Y To X
Range("J" & i).Value = "Retard < " & X & " jours"
Range("J" & i).Interior.ColorIndex = 46
Case -7 To -X
Range("J" & i).Value = " Avance < " & X & " jours "
Range("J" & i).Interior.ColorIndex = 43
Case Is > X
Range("J" & i).Value = " Retard > " & X & " jours "
Range("J" & i).Interior.ColorIndex = 3
Case Is < -X
Range("J" & i).Value = " Avance > " & X & " jours "
Range("J" & i).Interior.ColorIndex = 4
End Select
If Range("H" & i).Value = "" Then
Range("J" & i).Interior.ColorIndex = xlNone
Range("J" & i).Value = ""
End If
Next
End Sub
Merci d'avance pour vos suggestions!