Bonjour,
Le VBA est un ennemi sournois
En effet ,je me trouve confronté à un problème avec la macro vba .
Je ne sais pas pourquoi mais elle fait des caprices dans la comparaison.
Le but de la macro est de faire une comparaison de dates d'une colonne ("C*" de la feuille "DOS") avec la fonction "=AUJOURDHUI()-2" qui se trouve dans une cellule("H11") d'une feuille ("acceuil").
Suite à cette comparaison il doit colorer les lignes correspondantes
Cela marche mais de facon aléatoire avce ma macro
J ai dû utiliser la fonction left("C*",5) car le format des dates de la feuille dos (jj/mm/yyyy HH:MM) est different de celui de acceuil(jj/mm/yyyy)
Là je deviens chèvre !!!
Ci dessous mon code vba :
Sub condition()
'
' condition Macro
' Macro enregistrée le 13/05/2008 par dodoremix
'
'
Sheets("CLI").Select
pos_dans_feuille = Sheets("CLI").Range("A65536").End(xlUp).Row
'
For i = 2 To pos_dans_feuille
If Range("C" & i).Value <> "" Then
If Left(Range("C" & i).Value, 5) = Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
End With
ElseIf Left(Range("C" & i).Value, 5) < Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
End If
Next
Sheets("DOS").Select
pos_dans_feuille = Sheets("DOS").Range("A65536").End(xlUp).Row
'
For i = 2 To pos_dans_feuille
If Range("C" & i).Value <> "" Then
If Left(Range("C" & i).Value, 5) = Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
End With
ElseIf Left(Range("C" & i).Value, 5) < Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
End If
Next
End Sub
Y a t'il un problème avec ma comparaison ?
D'avance merci de votre aide
Le VBA est un ennemi sournois
En effet ,je me trouve confronté à un problème avec la macro vba .
Je ne sais pas pourquoi mais elle fait des caprices dans la comparaison.
Le but de la macro est de faire une comparaison de dates d'une colonne ("C*" de la feuille "DOS") avec la fonction "=AUJOURDHUI()-2" qui se trouve dans une cellule("H11") d'une feuille ("acceuil").
Suite à cette comparaison il doit colorer les lignes correspondantes
Cela marche mais de facon aléatoire avce ma macro
J ai dû utiliser la fonction left("C*",5) car le format des dates de la feuille dos (jj/mm/yyyy HH:MM) est different de celui de acceuil(jj/mm/yyyy)
Là je deviens chèvre !!!
Ci dessous mon code vba :
Sub condition()
'
' condition Macro
' Macro enregistrée le 13/05/2008 par dodoremix
'
'
Sheets("CLI").Select
pos_dans_feuille = Sheets("CLI").Range("A65536").End(xlUp).Row
'
For i = 2 To pos_dans_feuille
If Range("C" & i).Value <> "" Then
If Left(Range("C" & i).Value, 5) = Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
End With
ElseIf Left(Range("C" & i).Value, 5) < Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
End If
Next
Sheets("DOS").Select
pos_dans_feuille = Sheets("DOS").Range("A65536").End(xlUp).Row
'
For i = 2 To pos_dans_feuille
If Range("C" & i).Value <> "" Then
If Left(Range("C" & i).Value, 5) = Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 46
.Pattern = xlSolid
End With
ElseIf Left(Range("C" & i).Value, 5) < Left(Sheets("acceuil").Range("H11").Value, 5) Then
Range("A" & i & ":" & "J" & i).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
End If
Next
End Sub
Y a t'il un problème avec ma comparaison ?
D'avance merci de votre aide