Cell driven macro to copy a template sheet to other sheets

RPM7

Board Regular
Joined
Nov 28, 2007
Messages
191
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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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