VBA Help - Copying Data to specific sheet

quant1313

New Member
Joined
Jan 21, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am trying to copy a specific range of data from a sheet titled "Summary Template" to any worksheet that is not titled "Summary Template" or "Priority Admin" but I am continually getting an error message. Below is the code

VBA Code:
Sub Populate()
Dim ws As Worksheet
Dim lockedsheet As Worksheet
lockedsheet = Array("Summary Template", "Priority Admin")

Dim template As Worksheets
Set template = Worksheets("Summary Template")

For Each ws In ThisWorkbook.Sheets
    If Not ws.Name = lockedsheet.Name Then
        template.Range("A1:Y83").Copy
        ws.Range("A2").PasteSpecial (xlPasteAll)
    End If
Next ws

End Sub

Please help!
 
Last edited by a moderator:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Populate()
Dim ws As Worksheet
Dim template As Worksheets

Set template = Worksheets("Summary Template")

For Each ws In ThisWorkbook.Worksheets
   Select Case ws.Name
      Case "Summary Template", "Priority Admin"
      Case Else
         template.Range("A1:Y83").Copy
         ws.Range("A2").PasteSpecial (xlPasteAll)
   End Select
Next ws

End Sub
 
Upvote 0
Solution
the above worked
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Populate()
Dim ws As Worksheet
Dim template As Worksheets

Set template = Worksheets("Summary Template")

For Each ws In ThisWorkbook.Worksheets
   Select Case ws.Name
      Case "Summary Template", "Priority Admin"
      Case Else
         template.Range("A1:Y83").Copy
         ws.Range("A2").PasteSpecial (xlPasteAll)
   End Select
Next ws

End Sub
The above worked perfectly, thank you for the help. I have another question for you, if I wanted all sheets to be formatted the same (column width etc.) as the "Summary Template" except the Priority Admin sheet, do you know what the code for that would like ?
 
Upvote 0
As that is a different question, you will need to start a new thread.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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