Pasting a range into a sheet

Zain

New Member
Joined
Sep 4, 2007
Messages
43
I'm writing a macro that will create a large number of worksheets. I have one master worksheet with some data on it and I want to copy a range from the master to each of the new sheets. I'm thinking the following:

Dim myRange As Range

myRange = Sheets("Master").Range("A5:A100")

For k = 1 to 100
Set myWS = Worksheets.Add
myWSName = Sheets("Pivot").Cells(4, Col).Value
myWS.Name = myWSName
myWS.Range("A5:A100") = myRange
Next k

Wil this work? Is there a faster way to do it? Thanks.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,682
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
I think your code needs to be this (changes in bold):
Rich (BB code):
Dim myRange As Range
 
Set myRange = Sheets("Master").Range("A5:A100")
 
For k = 1 to 100
Set myWS = Worksheets.Add
myWSName = Sheets("Pivot").Cells(4, k).Value
myWS.Name = myWSName
myWS.Range("A5:A100") = myRange
Next k
though if you are just copying values across, I would use:

Rich (BB code):
Dim varData
varData = Sheets("Master").Range("A5:A100").Value
application.screenupdating = false
For k = 1 to 100
Set myWS = Worksheets.Add
myWSName = Sheets("Pivot").Cells(4, k).Value
myWS.Name = myWSName
myWS.Range("A5:A100").Value = varData
Next k
application.screenupdating = true
 
Upvote 0

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,723
Please describe exactly what you want. In English, with data examples if possible?

Is this a pivottable by any chance? Have you considered the Show Pages pivot command?
 
Upvote 0

Forum statistics

Threads
1,195,924
Messages
6,012,321
Members
441,690
Latest member
CyberWrek

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