Modules to worksheets and workbooks

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a workbook with 4 worksheets. I created a macro that works in one of the 4 worksheets. How do I get that same macro to work in all 4?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Maybe like this

Code:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    ws.Select
    Call mymacro
Next ws
 
Upvote 0
If it's Worksheet event code, the Workbook has events that operate on all the worksheets within it. For example this:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

in the ThisWorkbook module, is equivalent to:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

in a Worksheet module.
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,299
Members
448,885
Latest member
LokiSonic

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