Run a macro in another sheet from the one it was created in?

afs24

Board Regular
Joined
Sep 26, 2002
Messages
237
I created a macro and I want to be able to run it from any sheet in my workbook not just the one I created it in. Should I record the macro under new workbook?

How do I write the code so that all the steps I'm doing (pasting and deleting, etc.)are ran properly no matter what sheet I am in?

Sub Export_Scheduling_New()
'
' Export_Scheduling_New Macro
' Macro recorded 10/12/2002 by Anthony Steen
'

'
Selection.ClearContents
Range("F4").Select
Workbooks.Open Filename:= _
"J:PrimaryInbound Volume TrackingExport from scheduling.xls"
Windows("Master Fluff Log.xls").Activate
ActiveCell.FormulaR1C1 = _
"=SUM('Export from scheduling.xls'!R2C3:'Export from scheduling.xls'!R30000C3)"
Range("F5").Select
ActiveCell.FormulaR1C1 = _
"=SUMIF('Export from scheduling.xls'!R2C2:'Export from scheduling.xls'!R30000C2,""<>"",'Export from scheduling.xls'!R2C4:'Export from scheduling.xls'!R30000C4)"
Range("F4").Select
Selection.Copy
Worksheets("Export").Select
Range("E2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("F5").Select
Selection.Copy
Worksheets("Export").Select
Range("E3").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("F4:F5").Select
Selection.ClearContents
Range("A1").Select
Windows("Export from scheduling.xls").Activate
ActiveWindow.Close
Range("A1").Select
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Perhaps someone might have a better solution, but this is what I would do:

*make sure you are in the file where your original macro is located.

1. Choose Customize from the tools menu
2. Click on the commands tab
3. scroll down and select macro in the categories list
4. Drag the smily face to one of your toolbars on top
5. close the customize dialog box
6. click on the smily face on the toolbar.
7. Assign the macro to it.

Hope this helps.
 
Upvote 0
I need the macro to work on a specific sheet I don't need it on the toolbar. What's happening is the macro is running like it would on the orginal sheet for ever sheet it is ran on.
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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