0

I created a work book that would mimic the game yahtzee for a project. Through a macro I made it so you can hit a button to copy and paste a group of 9 cells that resemble the face of dice. Everything seems to work well but randomly I will get a run time error 1004. I did not write the code simply because I am not at that level yet. I have multiple different buttons within that do the same copy and paste but its not always the same one that gives me the error. Here is a copy of it. I would really appreciate any type of help on this.

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
        .Strikethrough = 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

Below is the section that is highlighted within the error...

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Community
  • 1
  • 1
Ryan
  • 1

1 Answers1

0

Try avoiding the use of .Select and use variables instead:

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
    .Strikethrough = 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
Community
  • 1
  • 1
BruceWayne
  • 22,923
  • 15
  • 65
  • 110