Copy & Paste VB codes to sheet modules.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
765
Hello friends, hope all is well!

I want to copy and paste the code:

Code:
Worksheet_Activate
Call copy_value
Call format
End sub

To every unhidden sheet’s module in the workbook.
The sheets are selected via the following code:

Code:
Sub SelectSheets()
    Dim mySheet As Object
    For Each mySheet In Sheets
        With mySheet
            If .Visible = True Then .Select Replace:=False
        End With
    Next mySheet
End Sub


Can you please help me with that challenge?

Thank you so much in advance!
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You could put this in the ThisWorkbook code module. It would run anytime a sheet is activated and you cannot activate a hidden sheet.

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Workbook_SheetActivate([COLOR=darkblue]ByVal[/COLOR] Sh [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR])
    [COLOR=darkblue]Call[/COLOR] copy_value
    [COLOR=darkblue]Call[/COLOR] Format
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Last edited:
Upvote 0
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_SheetActivate([color=darkblue]ByVal[/color] Sh [color=darkblue]As[/color] [color=darkblue]Object[/color])
    [color=darkblue]Select[/color] [color=darkblue]Case[/color] Sh.Name
        [color=darkblue]Case[/color] "DB", "format", "PT"   [color=green]'<--Excluded sheet names (case sensitive)[/color]
        [color=darkblue]Case[/color] [color=darkblue]Else[/color]
            [color=darkblue]Call[/color] copy_value
            [color=darkblue]Call[/color] Format
    [color=darkblue]End[/color] [color=darkblue]Select[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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