incompatibilité de type

Yldie

XLDnaute Junior
Cher(e)s internautes,

J'ai un message d'erreur "incompatibilité de type" qui ne bloque pas ma macro mais qui par contre ôte ma protection (et là ça me gêne un peu plus !!!), merci de bien vouloir m'aider

....................voici cette macro
Sub macro()
Dim Cellule As Range
ActiveSheet.Unprotect ("toto")
Application.ScreenUpdating = False
For Each Cellule In Range("B5:F139")
Select Case Cellule.Value
Case Is = ""
Cellule.Interior.ColorIndex = 0
Case Is = 0
Cellule.Interior.ColorIndex = 0
Cellule.Font.ColorIndex = 2
Case Is = "WE"
Cellule.Interior.ColorIndex = 48
Cellule.Font.ColorIndex = 2
Case Is = "piscine"
Cellule.Interior.ColorIndex = 34
Case Is = "muscu"
Cellule.Interior.ColorIndex = 40
Case Is = "R"
Cellule.Interior.ColorIndex = 41
Cellule.Font.ColorIndex = 2
Case Is = "sport"
Cellule.Interior.ColorIndex = 4
Case Is = "balade"
Cellule.Interior.ColorIndex = 38
Case Is = "P"
Cellule.Interior.ColorIndex = 44
Cellule.Font.ColorIndex = 1
Case Is = "vacances"
Cellule.Interior.ColorIndex = 39
Cellule.Font.ColorIndex = 2
End Select
Next Cellule
Range("a1").Select
Application.ScreenUpdating = True
ActiveSheet.Protect ("toto")
End Sub

Bonne soirée
 

jeanpierre

Nous a quitté
Repose en paix
Re : incompatibilité de type

Bonsoir Yldie, le forum,

Je viens de tester ta macro sur une plage une peu plus petite (sinon, c'est un peu long) et je n'ai pas rencontré de problème.

Peux-tu préciser ?

Bonne nuit.

Jean-Pierre
 

jeanpierre

Nous a quitté
Repose en paix
Re : incompatibilité de type

Bonsoir,

Message reçu ce jour en MP :

Merci Jean Pierre,

En effet, je l'ai essayé dans 1 nouvelle feuille excel (vierge) et cette macro fonctionne parfaitement. Or elle contient 2 autres macros d'impression (comme suit) d'où ma question : peut-il y avoir une mauvaise interaction entre celles ci et provoquer par là même une incompatibilité de type qui déverrouille mon mot de passe et donc toutes mes formules qui peuvent alors être supprimées (ce qui n'est pas souhaitable évidemment.......). Encore merci pour votre aide.


Sub macro()
Dim Cellule As Range
ActiveSheet.Unprotect ("toto")
Application.ScreenUpdating = False
For Each Cellule In Range("B5:F139")
Select Case Cellule.Value
Case Is = ""
Cellule.Interior.ColorIndex = 0
Case Is = 0
Cellule.Interior.ColorIndex = 0
Cellule.Font.ColorIndex = 2
Case Is = "WE"
Cellule.Interior.ColorIndex = 48
Cellule.Font.ColorIndex = 2
Case Is = "piscine"
Cellule.Interior.ColorIndex = 34
Case Is = "muscu"
Cellule.Interior.ColorIndex = 40
Case Is = "R"
Cellule.Interior.ColorIndex = 41
Cellule.Font.ColorIndex = 2
Case Is = "sport"
Cellule.Interior.ColorIndex = 4
Case Is = "balade"
Cellule.Interior.ColorIndex = 38
Case Is = "P"
Cellule.Interior.ColorIndex = 44
Cellule.Font.ColorIndex = 1
Case Is = "vacances"
Cellule.Interior.ColorIndex = 39
Cellule.Font.ColorIndex = 2
End Select
Next Cellule
Range("a1").Select
Application.ScreenUpdating = True
ActiveSheet.Protect ("toto")
End Sub

Sub mois1Imp_sauf_zero()
Dim Cellule As Range, MemImp As String
MemImp = Application.ActivePrinter
' Si aucune imprimante n'a été mémorisée
If Range("F1") = "" Then
' On demande à l'utilisateur d'en chosir une
Application.Dialogs(xlDialogPrinterSetup).Show
' On mémorise le choix de l'imprimante
Range("F1") = Application.ActivePrinter
End If
ActiveSheet.PageSetup.PrintArea = "$A$1:$F$25"
' Pour chaque cellule de L1 à Lx (x=dernière cellule remplie
For Each Cellule In Range("L1:L" & Range("L" & Rows.Count).End(xlUp).Row)
If Cellule <> 0 Then
Range("A25") = Cellule
ActiveSheet.PrintOut
End If
Next Cellule
' Remettre l'imprimante par défaut
Application.ActivePrinter = MemImp
End Sub

Sub mois2Imp_sauf_zero()
Dim Cellule As Range, MemImp As String
MemImp = Application.ActivePrinter
' Si aucune imprimante n'a été mémorisée
If Range("F1") = "" Then
' On demande à l'utilisateur d'en chosir une
Application.Dialogs(xlDialogPrinterSetup).Show
' On mémorise le choix de l'imprimante
Range("F1") = Application.ActivePrinter
End If
ActiveSheet.PageSetup.PrintArea = "$A$26:$F$48"
' Pour chaque cellule de L1 à Lx (x=dernière cellule remplie
For Each Cellule In Range("L1:L" & Range("L" & Rows.Count).End(xlUp).Row)
If Cellule <> 0 Then
Range("A25") = Cellule
ActiveSheet.PrintOut
End If
Next Cellule
' Remettre l'imprimante par défaut
Application.ActivePrinter = MemImp
End Sub

Pour te répondre,

Déjà, il n'y a pas d'interaction entre macros.

Pour le reste et à vue, rien ne me choque, mais je ne peux pas tester n'ayant pas d'imprimante à dispo.

Sinon, il faudrait voir le fichier (sans données confidentielles telles que Noms, etc.).

Sous format Zip, il devrait passer sur le forum. -48.8 Ko

Bonne soirée.

Jean-Pierre

Edit : j'en profite pour saluer Bruno
 
Dernière édition:
C

Compte Supprimé 979

Guest
Re : incompatibilité de type

Bonjour Yldie, bonjour JeanPierre ;)

Pour moi dans tes procédures, tu n'utilises pas de propriété pour ton Objet "Cellule", cela vient peut-être de là !?

Essaye dans ton code de mettre
Code:
' Pour chaque cellule de L1 à Lx (x=dernière cellule remplie)
For Each Cellule In Range("L1:L" & Range("L" & Rows.Count).End(xlUp).Row)
  If Cellule[B][COLOR=blue].Value[/COLOR][/B] <> 0 Then
    Range("A25") = Cellule[COLOR=blue][B].Value[/B][/COLOR]
    ActiveSheet.PrintOut
  End If
Next Cellule
A+
 

Staple1600

XLDnaute Barbatruc
Re : incompatibilité de type

Bonsoir à tous


Une autre version de ta macro

(Tu peux tester, spt, pour voir si tu vois une différence de rapidité )

Code:
Sub macro()
Dim Cellule As Range: Dim i As Long
ActiveSheet.Unprotect ("toto")
Application.ScreenUpdating = False
tb_1 = Split("0/WE/R/vacances", "/")
tb_2 = Split("0/48/41/39", "/")
tb_3 = Split("piscine/muscu/sport/balade", "/")
tb_4 = Split("34/40/4/38", "/")
For Each Cellule In Range("B5:F139")
If Not IsEmpty(Cellule) Then
For i = 0 To 3
Select Case Cellule.Value
Case Is = ""
Cellule.Interior.ColorIndex = 0
Case Is = tb_1(i)
Cellule.Font.ColorIndex = 2
Cellule.Interior.ColorIndex = tb_2(i)
Case Is = tb_3(i)
Cellule.Interior.ColorIndex = tb_4(i)
Case Is = "P"
Cellule.Font.ColorIndex = 1
Cellule.Interior.ColorIndex = 44
End Select
Next i
End If
Next Cellule
Application.ScreenUpdating = True
ActiveSheet.Protect ("toto")
End Sub
 
Dernière édition:

jeanpierre

Nous a quitté
Repose en paix
Re : incompatibilité de type

Bonsoir le fil,

Tenté plein de chose.

Je n'ai jamais reproduit ce message d'erreur.

Il nous faut donc ton fichier, tel qu'il est, avec ses macros...

D'ici et à distance, difficile de faire mieux.

A te lire et en attente de ton fichier récalcitrant.

Bonne nuit.

Jean-Pierre
 

Discussions similaires

Statistiques des forums

Discussions
312 231
Messages
2 086 455
Membres
103 216
dernier inscrit
LoshR7