a condition

drisou

XLDnaute Occasionnel
Bonjour le forum,
dans ma feuille de calcul, dans la colonne "c" j'ai des dates ,lorsque le mois se termine par 30 , la cellule concernée se colorie en rouge via mon code, mon probleme est que je ne sais pas comment faire pour que lorsque le mois se termine par 31 la cellule qui contient 31 se colorie en rouge et pas aussi la cellule qui contient 30.

merci pour votre aide.

voici mon bout de code:

Sub inventaire()

Dim x As Variant


For x = Range("c65500").End(xlUp).Row - 280 To Range("c65500").End(xlUp).Row

If Left(Cells(x, 3), 2) = 31 Then

Cells(x, 3).Interior.ColorIndex = 3

else

If Left(Cells(x, 3), 2) <> 31 and Left(Cells(x, 3), 2) = 30 Then


Cells(x, 3).Interior.ColorIndex = 3

End If
End if
Next


End Sub
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : a condition

Bonsoir Drisou, bonsoir le forum,

Peut-être comme ça :
Code:
Sub inventaire()
Dim x As long

For x = Range("C65500").End(xlUp).Row - 280 To Range("C65500").End(xlUp).Row
    Cells(x, 3).Interior.ColorIndex = IIf(Left(Cells(x, 3), 2) = 31, 3, xlNone): Exit Sub
    Cells(x, 3).Interior.ColorIndex = IIf(Left(Cells(x, 3), 2) = 30, 3, xlNone)
Next
End Sub
 

jpb388

XLDnaute Accro
Re : a condition

Bonsoir à tous
essaye ça

Code:
Sub inventaire()

 Dim x As Long
 For x = Range("c65500").End(xlUp).Row - 280 To Range("c65500").End(xlUp).Row
 If Month(Range("C" & x).Value + 1) <> Month(Range("C" & x).Value) Then
    Cells(x, 3).Interior.ColorIndex = 3
 End If
 Next
 End Sub
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : a condition

Bonsoir le fil, bonsoir le forum,

Sans fichier exemple difficile de trouver la bonne réponse... Essaie comme ça :
Code:
Sub inventaire()
Dim x As long

For x = Range("C65500").End(xlUp).Row - 280 To Range("C65500").End(xlUp).Row
    Cells(x, 3).Interior.ColorIndex = IIf(Day(Cells(x, 3)) = 31, 3, xlNone): Exit Sub
    Cells(x, 3).Interior.ColorIndex = IIf(Day(Cells(x, 3)) = 30, 3, xlNone)
Next
End Sub
 

drisou

XLDnaute Occasionnel
Re : a condition

pour l'exemple j'ai pris juste un fichier ou j'ai mis les dates dans la colonne "c".
fichier ci -joint.
 

Pièces jointes

  • test.xlsm
    12.6 KB · Affichages: 37
  • test.xlsm
    12.6 KB · Affichages: 36
  • test.xlsm
    12.6 KB · Affichages: 38

jpb388

XLDnaute Accro
Re : a condition

Re
ton essai ne compte que 32 ligne et commence a la ligne 1
j'ai modifié ma macro en conséquence
 

Pièces jointes

  • test.xlsm
    14 KB · Affichages: 41
  • test.xlsm
    14 KB · Affichages: 40
  • test.xlsm
    14 KB · Affichages: 39

Robert

XLDnaute Barbatruc
Repose en paix
Re : a condition

Bonsoir le fil, bosnoir el forum,

Une solution proche de celle de Jpb :
Code:
Sub inventaire()
Dim x As Long
For x = Range("C65500").End(xlUp).Row - 280 To Range("C65500").End(xlUp).Row
    If Month(Cells(x, 3).Value) <> Month(Cells(x - 1, 3).Value) Then Cells(x - 1, 3).Interior.ColorIndex = 3
Next x
End Sub
 

drisou

XLDnaute Occasionnel
Re : a condition

Bonsoir le forum,
jpb388 , Robert , merci a vous
ca fonctionne impeccable,
mon probleme était que dans la colonne "c" j'avais entre les dates ,des cellules contenant du texte,

en rajoutant une condition pour agir sur les cellules avec des valeurs numérique c'est bon.

désolé car j'avais ma demande était incomplète.

merci encore et bonne soirée.
 

Discussions similaires

Réponses
1
Affichages
205
Réponses
0
Affichages
185

Statistiques des forums

Discussions
312 602
Messages
2 090 156
Membres
104 413
dernier inscrit
HMF1984