Assign Macro to button and won't switch sheets

Nerdalert314

New Member
Joined
Mar 28, 2018
Messages
23
Good afternoon,

I created the following macro to move a few numbers and then clear data from cells. The macro works perfect. I was hoping to add a clear button for some to just push when they needed to clear the spreadsheet. When assigning the macro to the button (on sheet "Blotter") it tries to process the whole macro on this sheet. It doesn't read selecting the other sheets and it eventually errors out. I have never used buttons before. Can anyone provide insight?


HTML:
Sub Clear()
'
' Clear Macro
    Sheets("Blotter").Select
    Range("C9").Copy
    Range("K6").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("K44").Copy
    Range("K4").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("K44,K10:K14, K17:K18, K25:K31").FormulaR1C1 = "0"
    Range("E10:E15,E17:E35, D49:D51").ClearContents
    Sheets("Difference Ticket Totals").Select
    Range("B4").Copy
    Range("B1").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Shadow Posting").Select
    Range("B6:D6").Copy
    Range("B2").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B6:D6").ClearContents
    Range("B12:C12,B17:C17,B26:C26,B34:C34,E12:E15,E17:E24,E26:E32,E34:E38,G24,G32,G34:G38").ClearContents
    Sheets("Outstanding Checks").Select
    Range("B3:B9").Copy
    Range("C3").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B6:B8").FormulaR1C1 = "0"
    Sheets("BLP Balances").Select
    Range("B6").Copy
    Range("B2").PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B6, E2:E3").FormulaR1C1 = "0"
        Sheets("Staff Proofs-BCS").Select
    Range("D97:D98, E97:E98, G97:G98").FormulaR1C1 = "0"
    Range("A67:A86").FormulaR1C1 = "NDT"
    Range("A67:A86").Select
    With Selection.Interior
        .Pattern = xlNone
    End With
    Range("B4:Q17, B19:Q54, B59:Q86").FormulaR1C1 = "0"
    Range("A35:A54").FormulaR1C1 = "CDT#"
    Range("A35:A54").Select
   
    With Selection.Interior
        .Pattern = xlNone
    End With
 
    Sheets("Blotter").Select
    Range("B1:M1").Select
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
What error message do you get & what line is highlighted?
 
Upvote 0
Hi Fluff,

Thanks for being willing to help. I added "Sheets("NAMEHERE")." In front of every Range and it worked.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top