Erreur d'exécution Excel copyr et coller

J'ai créé un carnet de travail qui imite le jeu yahtzee pour un projet. Grâce à une macro, je l'ai fait pour que vous puissiez bash un button pour copyr et coller un groupe de 9 cellules qui ressemblent au visage des dés. Tout semble fonctionner bien, mais randomment, j'aurai une erreur d'exécution 1004. Je n'ai pas écrit le code simplement parce que je ne suis pas encore à ce niveau. J'ai plusieurs buttons différents qui font la même copy et colle, mais ce n'est pas toujours le même qui me donne l'erreur. Voici une copy de celui-ci. J'apprécierais tout type d'aide à ce sujet.

Sub Hold4() ' ' Hold4 Macro ' ' Selection.Copy Range("N10").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False With Selection.Font .Name = "Wingdings 2" .Size = 28 .Ssortingkethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ThemeColor = xlThemeColorLight1 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With Range("N2:P4").Select With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End Sub 

Voici la section qui est mise en évidence dans l'erreur …

 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 

Essayez d' éviter l'utilisation de .Select et utilisez les variables à la place:

 Sub Hold4() Dim myRng As Range Set myRng = Selection myRng.Copy Range("N10").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False With myRng.Font .Name = "Wingdings 2" .Size = 28 .Ssortingkethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ThemeColor = xlThemeColorLight1 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With Range("N2:P4") With .Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With With .Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End With End Sub