S
SmartyPants
I am trying to set up a button that clears cells over several
worksheets.
But when it tries to switch to another worksheet, I get this error
-1004.
It say "select method of range class failed"
How can I correct this problem?
Here is the code I am using:
Sheets("Production").Select
Range("D4").Select
Selection.ClearContents
Range("F4").Select
Selection.ClearContents
Range("H4").Select
Selection.ClearContents
Range("D710").Select
Selection.ClearContents
Range("F7:F10").Select
Selection.ClearContents
Range("H7:H10").Select
Selection.ClearContents
Range("N3").Select
Selection.ClearContents
Range("L6:Q13").Select
Selection.ClearContents
Range("D1724").Select
Selection.ClearContents
Range("F17:F24").Select
Selection.ClearContents
Range("H17:H24").Select
Selection.ClearContents
Range("M17:Q24").Select
Selection.ClearContents
Range("L29:Q38").Select
Selection.ClearContents
Range("B34:B38").Select
Selection.ClearContents
Range("E34:I38").Select
Selection.ClearContents
Range("B43:N51").Select
Selection.ClearContents
Sheets("Hours").Select
Range("D712").Select (This is where the error occurs)
Selection.ClearContents
Range("F7:F12").Select
Selection.ClearContents
Range("G13:K13").Select
Selection.ClearContents
Range("M1313").Select
Selection.ClearContents
Range("D1419").Select
Selection.ClearContents
Range("F14:F19").Select
Selection.ClearContents
Range("G20:K20").Select
Selection.ClearContents
Range("M2020").Select
Selection.ClearContents
Range("D2126").Select
Selection.ClearContents
Range("F21:F26").Select
Selection.ClearContents
Range("G27:K27").Select
Selection.ClearContents
Range("M2727").Select
Selection.ClearContents
Range("D2833").Select
Selection.ClearContents
Range("F28:F33").Select
Selection.ClearContents
Range("G34:K34").Select
Selection.ClearContents
Range("M3434").Select
Selection.ClearContents
Range("C35:F40").Select
Selection.ClearContents
Range("G41:K41").Select
Selection.ClearContents
Range("M4141").Select
Selection.ClearContents
Range("C28:F33").Select
Selection.ClearContents
Range("C21:F26").Select
Selection.ClearContents
Range("C14:F19").Select
Selection.ClearContents
Range("C7:F12").Select
Selection.ClearContents
Range("Q7:U41").Select
Selection.ClearContents
Range("A46:X58").Select
Selection.ClearContents
Sheets("Salary Absentees").Select
Range("A5:C24").Select
Selection.ClearContents
Sheets("No Tires").Select
Range("B4:L40").Select
Selection.ClearContents
Sheets("Production").Select
Range("N3").Select
worksheets.
But when it tries to switch to another worksheet, I get this error
-1004.
It say "select method of range class failed"
How can I correct this problem?
Here is the code I am using:
Sheets("Production").Select
Range("D4").Select
Selection.ClearContents
Range("F4").Select
Selection.ClearContents
Range("H4").Select
Selection.ClearContents
Range("D710").Select
Selection.ClearContents
Range("F7:F10").Select
Selection.ClearContents
Range("H7:H10").Select
Selection.ClearContents
Range("N3").Select
Selection.ClearContents
Range("L6:Q13").Select
Selection.ClearContents
Range("D1724").Select
Selection.ClearContents
Range("F17:F24").Select
Selection.ClearContents
Range("H17:H24").Select
Selection.ClearContents
Range("M17:Q24").Select
Selection.ClearContents
Range("L29:Q38").Select
Selection.ClearContents
Range("B34:B38").Select
Selection.ClearContents
Range("E34:I38").Select
Selection.ClearContents
Range("B43:N51").Select
Selection.ClearContents
Sheets("Hours").Select
Range("D712").Select (This is where the error occurs)
Selection.ClearContents
Range("F7:F12").Select
Selection.ClearContents
Range("G13:K13").Select
Selection.ClearContents
Range("M1313").Select
Selection.ClearContents
Range("D1419").Select
Selection.ClearContents
Range("F14:F19").Select
Selection.ClearContents
Range("G20:K20").Select
Selection.ClearContents
Range("M2020").Select
Selection.ClearContents
Range("D2126").Select
Selection.ClearContents
Range("F21:F26").Select
Selection.ClearContents
Range("G27:K27").Select
Selection.ClearContents
Range("M2727").Select
Selection.ClearContents
Range("D2833").Select
Selection.ClearContents
Range("F28:F33").Select
Selection.ClearContents
Range("G34:K34").Select
Selection.ClearContents
Range("M3434").Select
Selection.ClearContents
Range("C35:F40").Select
Selection.ClearContents
Range("G41:K41").Select
Selection.ClearContents
Range("M4141").Select
Selection.ClearContents
Range("C28:F33").Select
Selection.ClearContents
Range("C21:F26").Select
Selection.ClearContents
Range("C14:F19").Select
Selection.ClearContents
Range("C7:F12").Select
Selection.ClearContents
Range("Q7:U41").Select
Selection.ClearContents
Range("A46:X58").Select
Selection.ClearContents
Sheets("Salary Absentees").Select
Range("A5:C24").Select
Selection.ClearContents
Sheets("No Tires").Select
Range("B4:L40").Select
Selection.ClearContents
Sheets("Production").Select
Range("N3").Select