Fill across sheets - except one?

123excel

New Member
Joined
Jan 18, 2017
Messages
34
Hi, i´m using the macro below to copy data from one sheet to all other sheets. It works great but i would like to exclude one page named statistics. Anyone who knows how to do it?

The macro:
Code:
Dim ws As Worksheet
    Sheets.FillAcrossSheets ws.Range("F5:H5")
    Set ws = ThisWorkbook.Sheets("NewAgency")
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi 123excel,

You could just clear the range from that tab after the data has been put there:

Code:
Option Explicit
Sub Macro2()
    
    With ThisWorkbook
        .Sheets.FillAcrossSheets ThisWorkbook.Sheets("NewAgency").Range("F5:H5")
        .Sheets("statistics").Range("F5:H5").ClearContents
    End With

End Sub

Another (though in my humble less efficient) way to do it would be loop through each tab but ignore the one called statistics.

Regards,

Robert
 
Upvote 0
Hi Trebor76! I can´t clear the range, cause there is other data on the statistic sheet that would be erased. How do you loop throught each tab? I also forgot to mention that new tabs/sheets are added time to time (through another macro), so i cant make a loop with a fixed number of sheets.
 
Upvote 0
Hi, i tried another macro. This macro is doing the job, every page is changed except Statistics and Info, but at the end i get "object_worksheet failed" error, and it stops the macro to keep going (more actions are done after this part of the macro). It is sh.Select that gets yellow marked when running the debugger. Any ideas what could be wrong? I have some hided sheets, maybe thats the cause? Even if so, I dont want to make them visible again..

Code:
Sheets("NewAgency").Activate
    Range("F5:H5").Select
    Selection.Copy
    Dim sh As Worksheet
    
For Each sh In ActiveWorkbook.Worksheets
    If sh.Name <> "Statistics" And sh.Name <> "Info" Then
        sh.Select
    
    Range("F5").Select
    ActiveSheet.Paste
        
         End If
Next sh
 
Upvote 0
Hi 123excel,

Yes the problem is that you're trying to select a tab that's hidden. In the majority of cases you don't need to select a tab to work with it.

See how this goes:

Code:
Option Explicit
Sub Macro1()

    Dim wsMySheet As Worksheet
    
    Application.ScreenUpdating = False

    For Each wsMySheet In ActiveWorkbook.Worksheets
        If wsMySheet.Name <> "Statistics" And wsMySheet.Name <> "Info" Then
            Sheets("NewAgency").Range("F5:H5").Copy Destination:=wsMySheet.Range("F5")
        End If
    Next wsMySheet
    
    Application.ScreenUpdating = True
    
End Sub

Regards,

Robert
 
Upvote 0
Or if you don't want to paste to the hidden worksheets :

Code:
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
    If sh.Name <> "Statistics" And sh.Name <> "Info" And sh.Visible Then _
        Sheets("New Agency").Range("F5:H5").Copy sh.Range("F5")
Next sh

There no need to turn off ScreenUpdating - the code doesn't involve any screen updating.
 
Upvote 0

Forum statistics

Threads
1,216,203
Messages
6,129,490
Members
449,512
Latest member
Wabd

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