erreur 1004 sur une mise en forme conditionelle

Cipic

XLDnaute Nouveau
Bonjour,

Je suis entrain de construire une petite mais utile macro de mise en forme.

Une étape consiste à appliquer une mise en forme en fonction du nombre d'espaces vides dans la premiere cellule et celà fonctionne. je voudrais pouvoir appliquer cette mise en forme à toute la ligne, mais je n'y parviens pas.

Un message d'erreur 1004 s'affiche.

Je pensais y parvenir en changeant la plage de sélection mais celà ne suffit pas.

Quelqu'un peut-il m'aider?

merci beaucoup par avance.

romain


Columns("A:A").Select
Selection.NumberFormat = "General"
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=CHERCHE(STXT(SUPPRESPACE(A1);1;1);A1)-1=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10498160
.TintAndShade = 0
End With
 

PMO2

XLDnaute Accro
Re : erreur 1004 sur une mise en forme conditionelle

Bonjour,

Au sujet de l'erreur 1004, je pense que votre code a du déjà tourner au moins 3 fois. Excel limite le nombre de MFC à 3 et, si vous relancez votre macro, vous essayez d'en rajouter une quatrième ce qui a pour conséquence le plantage du programme.

Dans la mesure où c'est bien cela et pour s'en convaincre, veuillez faire un test avec votre code modifié ci-dessous

Code:
Sub Test_pmo()
Columns("A:A").Select
Selection.NumberFormat = "General"

'--- Test d'existence de 3 MFC ---
Dim reponse&
Dim A$
Dim FC As FormatCondition
With Selection
  If .FormatConditions.Count = 3 Then
    For Each FC In .FormatConditions
      A$ = A$ & FC.Formula1 & vbCrLf
    Next FC
    reponse& = MsgBox(prompt:="Il y a déjà 3 mises en forme." & vbCrLf & vbCrLf & _
      A$ & vbCrLf & "Voulez-vous les supprimer ?", _
      Buttons:=vbOKCancel + vbDefaultButton2, Title:="Excel n'accepte pas plus de 3 MFC")
    If reponse& = vbOK Then
      On Error Resume Next
      .FormatConditions.Delete
      Application.Dialogs(xlDialogConditionalFormatting).Show 'Pour visualiser (inutile)
      On Error GoTo 0
    End If
    Exit Sub
  End If
End With
'----------------------------------

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=CHERCHE(STXT(SUPPRESPACE(A1);1;1);A1)-1=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10498160
.TintAndShade = 0
End With
End Sub


Cordialement.

PMO
Patrick Morange
 

Statistiques des forums

Discussions
312 492
Messages
2 088 899
Membres
103 982
dernier inscrit
krakencolas