copy data on all sheets except specified sheets

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to copy data from row B3 to the last row containing data in C3 on all sheets except specified sheets and all formulas to remain intact-see specified sheets not to be affected in code for eg Main Menu, YTD-Dashboard etc

Row B3 onwards in being copied on some of the specified sheets and paste valued into Col C


It would be appreciated if someone could kindly amend my formula



Code:
 Sub Copy_Data()
Dim lr As Long, ws As Worksheet
For Each ws In Worksheets
    If ws.Name <> "Main Menu" And ws.Name <> "YTD" And ws.Name <> "YTD-Dashboard" And ws.Name <> "Expenses" And _
        ws.Name <> "YTD-Including Units" And ws.Name <> "Months" And ws.Name <> "Monthly Data detail" _
        And ws.Name <> "Scroll Bar By Month" And ws.Name <> "YTD Filtered Data" Then
        lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
        ws.Range("B3:B" & lr).Copy
        ws.Range("C3").PasteSpecial xlPasteValues
    End If
Next ws
Application.CutCopyMode = False
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Howard,

See how this goes:

Code:
Option Explicit
Sub Macro2()

    Dim varMyArray As Variant
    Dim wsMySheet  As Worksheet
    Dim lngLastRow As Long
    
    varMyArray = Array("Main Menu", "YTD", "YTD-Dashboard", "Expenses", "YTD-Including Units", "Months", "Monthly Data detail", "Scroll Bar By Month", "YTD Filtered Data")
    
    Application.ScreenUpdating = False
    
    For Each wsMySheet In ThisWorkbook.Sheets
        'If the sheet name is not the in 'varMyArray' array, then...
        If IsNumeric(Application.Match(wsMySheet.Name, varMyArray, 0)) = False Then
            With wsMySheet
                lngLastRow = .Cells(Rows.Count, "B").End(xlUp).Row
                '...copy all the formulas from cell B3 to C3 as values
                .Range("B3:B" & lngLastRow).Copy
                .Range("C3").PasteSpecial xlPasteValues
            End With
        End If
    Next wsMySheet
    
    Application.ScreenUpdating = True
    
End Sub

Regards,

Robert
 
Upvote 0
Thanks for the help Robert. Have teste the code and it works perfectly
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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