Cell driven macro to copy a template sheet to other sheets

RPM7

Board Regular
Joined
Nov 28, 2007
Messages
182
I have a macro for copying a template worksheet and pasting it over specific sheets when a named cell (Overwrite_Sheetn) says "Yes".
It's not elegant, and only works some of the time.
For some reason some of the sheets won't copy and paste the template file.
I have 20 sheets that can be overwritten (Overwrite_Sheet1 to Overwrite_Sheet20)

NB: The below snippet is only showing the first three instances.

VBA Code:
Sub Copy_Template()
'
' 7.0 Template_Copy Macro
'
'
    Application.ScreenUpdating = False
    
If [Overwrite_Sheet1] = "Yes" Then
    Sheets("Template").Select
    Cells.Select
    Selection.Copy
    Worksheets(1).Select
    Cells.Select
    ActiveSheet.Paste
End If

If [Overwrite_Sheet2] = "Yes" Then
    Sheets("Template").Select
    Cells.Select
    Selection.Copy
    Worksheets(2).Select
    Cells.Select
    ActiveSheet.Paste
End If

If [Overwrite_Sheet3] = "Yes" Then
    Sheets("Template").Select
    Cells.Select
    Selection.Copy
    Worksheets(3).Select
    Cells.Select
    ActiveSheet.Paste
End If

    Application.ScreenUpdating = True
End Sub


Can someone point out where I'm going wrong?

Or is there a better way of doing this?

Thanks
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
Hello,

does this work as expected?

VBA Code:
Sub Copy_Template()
    Application.ScreenUpdating = False
    For MY_SHEET = 1 To 2 '20
        If Range("OverwriteSheet" & MY_SHEET).Value = "YES" Then
            Sheets("Template").Select
            Cells.Select
            Selection.Copy
            Worksheets("Overwritesheet" & MY_SHEET).Select
            Cells.Select
            ActiveSheet.Paste
        End If
    Next MY_SHEET
    Application.ScreenUpdating = True
End Sub

there may be many reasons why some sheets don't get copies.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,826
Messages
5,627,117
Members
416,223
Latest member
RichardHell

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
Top