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.
 
You'll want to refrain from ActiveWindow, ActiveSheet, ActiveCell when you are trying to run code on multiple sheets.
Hi thanks fir reply so does that mean that in my case it isn't possible to achieve what I'm after?
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
It is possible, but could you give us the names of the 3 sheets involved (in order as per you posted macros)
 
Upvote 0
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
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
Hi
 
Upvote 0
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
Hi Kevin this is working fine apart from one thing. The first cell in each sheet K9 is not changing to the new figure but the rest is fine. When I run the macros 1000, 6.4 and 2 show up in K9 instead of new figures.
 
Upvote 0
K9 is not changing to the new figure but the rest is fine. When I run the macros 1000, 6.4 and 2 show up in K9 instead of new figures.
What are the "new figures" meant to be? According to your code in post #9, this:
Range("K9").Select
ActiveCell.FormulaR1C1 = "1000"
and this
Range("K9").Select
ActiveCell.FormulaR1C1 = "6.4"
Range("K9").Select
ActiveCell.FormulaR1C1 = "6.4"
and this
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
Range("K9").Select
ActiveCell.FormulaR1C1 = "2"
would have put those figures in K9 of the respective sheets. What are the figures meant to be, and where do they come from?
It would be better if you could provide copies of your sheets using the XL2BB add in, or better still, share your file via Google Drive, Dropbox or similar file sharing platform showing a before-and-after scenario so I know what your aim is.
 
Upvote 0
What are the "new figures" meant to be? According to your code in post #9, this:

and this

and this

would have put those figures in K9 of the respective sheets. What are the figures meant to be, and where do they come from?
It would be better if you could provide copies of your sheets using the XL2BB add in, or better still, share your file via Google Drive, Dropbox or similar file sharing platform showing a before-and-after scenario so I know what your aim is.
Hi I took out the first line on the sheet and works perfect now thankyou.
 
Upvote 0
Happy it works for you now, although I don't understand how taking out the first line makes any difference to what my code puts in cell K9 of each sheet?! Still, as long as it works now (y)
 
Upvote 0
Happy it works for you now, although I don't understand how taking out the first line makes any difference to what my code puts in cell K9 of each sheet?! Still, as long as it works now (y)
Sorry not very clear, what I did was take out the lines with the 1000, 6.4 and the 2 in them. Now k9 to k48 copies perfectly.
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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