Macros in different sheets

Erantes

New Member
Joined
Dec 27, 2023
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi I am fairly new to excel with a problem I cant solve so help would be great. I have 10 sheets with a macro on each sheet that I want to trigger at the same time. I have looked at loads of YouTube videos but whatever I do it only seems to trigger on the sheet I'm on and none of the other sheets.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try the following on a copy of your workbook. You must change the names of your sheets to their actual names.
VBA Code:
Option Explicit
Sub Erantes()
    Application.ScreenUpdating = False
    Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Set ws1 = Worksheets("Sheet1")  '<--- *** You need to change the names of the 3 sheets to their actual names ***
    Set ws2 = Worksheets("Sheet2")
    Set ws3 = Worksheets("Sheet3")
    
    With ws1
        .Range("K9") = "1000"
        .Range("K9:K48").Copy
        .Range("K53").PasteSpecial xlPasteValues
        .Range("C2").Copy
        .Range("C53").PasteSpecial xlPasteValues
    End With
    Application.CutCopyMode = 0
    
    With ws2
        .Range("K9") = "6.4"
        .Range("K9:K48").Copy
        .Range("K53").PasteSpecial xlPasteValues
        .Range("C2").Copy
        .Range("C53").PasteSpecial xlPasteValues
    End With
    Application.CutCopyMode = 0
    
    With ws3
        .Range("K9") = "2"
        .Range("K9:K48").Copy
        .Range("K53").PasteSpecial xlPasteValues
        .Range("C2").Copy
        .Range("C53").PasteSpecial xlPasteValues
    End With
    Application.CutCopyMode = 0
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
How do you want to "trigger" them? Do they all do the same thing, just on a different Sheet?
 
Upvote 0
You haven't answered @Skyybot 's question as to how you want to Trigger the code?
Hi so each macro is to collect information at a certain time on each sheet say 8am. I would like to run one macro that would activate the 10 macros at roughly the same time.
 
Upvote 0
Just call the other Macros from the one you run. Example:
VBA Code:
Sub Sheet1Macro() 'This is in Sheet1
'Do stuff
End Sub

Sub Sheet2Macro() 'This is in Sheet2
'Do stuff
End Sub

Sub YourMainMacro() 'Put this in ThisWorkbook
Sheet1.Sheet1Macro
Sheet2.Sheet2Macro
End Sub
 
Upvote 0
Can you post the macro you currently have on "each sheet"? Only once if they're the same.
 
Upvote 0
Sub RACE1TIME0730()
'
' RACE1TIME0730 Macro
'

'
Range("K9").Select
ActiveCell.FormulaR1C1 = "1000"
Range("K9:K48").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=28
Range("K53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-28
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=39
Range("C53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub RACE2TIME0730()
'
' RACE2TIME0730 Macro
'

'
Range("K9").Select
ActiveCell.FormulaR1C1 = "6.4"
Range("K9").Select
ActiveCell.FormulaR1C1 = "6.4"
Range("K9:K48").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=19
Range("K53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-19
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=34
Range("C53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub RACE3TIME0730()
'
' RACE3TIME0730 Macro
'

'
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
Range("K9:K48").Select
Selection.Copy
Range("AF1").Select
ActiveWindow.SmallScroll Down:=28
Range("K53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-28
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=28
Range("C53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,172
Messages
6,129,291
Members
449,498
Latest member
Lee_ray

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