Bonjour,
je travaille sur excel 2010 et j'ai fait beaucoup de vb.
Pour la première fois, je travaille sur la mise en forme conditionnelle avec vb.
ça a fonctionné mais maintenant il bloque sur le .formatcond... ou autre .interior.... que j'utilise avec mon with range...
'erreur d'exécution 1004'
erreur définie par lapplication ou l'objet
Je joins mon code car le fichier est trop gros:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim i As Integer
Dim DerCol As Integer
Dim val1 As Integer
Dim val2 As Integer
Dim colonne As String
Worksheets("Feuil1").Protect , UserInterFaceOnly:=True
DerCol = Range("G6:ZZ6").End(xlToRight).Column
For i = 2 To 5
'MsgBox "val 1 : " & Worksheets("Paramétrage").Cells(i, 2).Value & " val 2 " & Worksheets("Paramétrage").Cells(i + 1, 2).Value
val1 = Worksheets("Paramétrage").Cells(i, 2).Value + 1
val2 = Worksheets("Paramétrage").Cells(i + 1, 2).Value - 1
colonne = NomDeColonne(DerCol)
With Range("G" & val1 & ":" & colonne & val2) 'Sélection des plages où doit s'appliquer la MeF
'Supprime les MFC existantes
.FormatConditions.Delete
.Interior.Color = xlNone
'Ajoute une condition (Vrai lorsque la cellule est non vide)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:=" "
With .FormatConditions(1)
'Définit la couleur de fond de la cellule lorsque la condition sera vraie.
Select Case i
Case 2
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 3
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 4
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 5
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
End Select
' .Interior.ColorIndex = 15 'Gris
End With
End With
Next i
End Sub
Est-ce que quelqu'un pourrait m'aider, je suis dessus depuis 1 heure + forums...
je travaille sur excel 2010 et j'ai fait beaucoup de vb.
Pour la première fois, je travaille sur la mise en forme conditionnelle avec vb.
ça a fonctionné mais maintenant il bloque sur le .formatcond... ou autre .interior.... que j'utilise avec mon with range...
'erreur d'exécution 1004'
erreur définie par lapplication ou l'objet
Je joins mon code car le fichier est trop gros:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim i As Integer
Dim DerCol As Integer
Dim val1 As Integer
Dim val2 As Integer
Dim colonne As String
Worksheets("Feuil1").Protect , UserInterFaceOnly:=True
DerCol = Range("G6:ZZ6").End(xlToRight).Column
For i = 2 To 5
'MsgBox "val 1 : " & Worksheets("Paramétrage").Cells(i, 2).Value & " val 2 " & Worksheets("Paramétrage").Cells(i + 1, 2).Value
val1 = Worksheets("Paramétrage").Cells(i, 2).Value + 1
val2 = Worksheets("Paramétrage").Cells(i + 1, 2).Value - 1
colonne = NomDeColonne(DerCol)
With Range("G" & val1 & ":" & colonne & val2) 'Sélection des plages où doit s'appliquer la MeF
'Supprime les MFC existantes
.FormatConditions.Delete
.Interior.Color = xlNone
'Ajoute une condition (Vrai lorsque la cellule est non vide)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:=" "
With .FormatConditions(1)
'Définit la couleur de fond de la cellule lorsque la condition sera vraie.
Select Case i
Case 2
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 3
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 4
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
Case 5
.Interior.Color = Cells(Worksheets("Paramétrage").Cells(i, 2), 2).Interior.Color
End Select
' .Interior.ColorIndex = 15 'Gris
End With
End With
Next i
End Sub
Est-ce que quelqu'un pourrait m'aider, je suis dessus depuis 1 heure + forums...