macro, copy, paste, create new sheet from template sheet.

stpbby

New Member
Joined
May 28, 2010
Messages
6
I have two worksheets in one workbook... The worksheet 'data' contains some data that I need to copy and paste into certain cells in another worksheet called 'form'. for each row of data I need a new worksheet created from the 'form' worksheet.

Basically for each row of data in my 'data' worksheet (321 rows) I need a new worksheet created from my template worksheet 'form'. the data that I need copied from the 'data' worksheet is in cols B-G, and I need this data pasted into the 'Form' worksheet into cells B4 - G4.
The names of the new worksheets created doesnt matter, i suppose they just have to be unique.

Also I would like to fill in the date field which is located in column J in my 'data' worksheet and have this pasted into H8 in my 'form' worksheets.

Also, the rows of data will change daily, it will not always be 321 rows.

I'm fairly new to VB... So any help would be GREATLY appreciated!

btw, I am using office 2k3 on Windows 7.

I tried using this code to create the new worksheets, it worked but, it only creates 254 new worksheets then errors out.
Option Explicit

Sub Copy_Sheets()

Dim i As Integer
Dim wks As Worksheet

Set wks = Sheets("data")

For i = 1 to 360
Sheets("form").Copy After:=Sheets(2)
ActiveSheet.Name = wks.Cells(i, 2)
ActiveSheet.Cells(1, 2)=wks.Cells(i, 2)
Next

End Sub​
Thanks!!

-Brad
<!-- / message --> <!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --> <!-- END TEMPLATE: ad_showthread_firstpost_sig --> <!-- controls -->
progress.gif
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I have a macro here:
On that page, the parts you need to edit are colored to draw your attention to them, but this macro is basically what you're after.

There's a sample workbook, too, so you can compare how the sample macro executes on sample data, should give you a better understanding and help you make the changes you need for your sheet(s).
 
Upvote 0
This macro works , but it errors out with " run-time error "1004": Method of 'copy' of object_worksheet failed.

when I choose 'debug, it highlights the line below
tSht.Copy After:=Worksheets(Worksheets.Count) 'copy the template

It does this after creating 256 workbooks...
 
Upvote 0
You must be running into some sort of memory limitations on your own system.

I use Excel 2003. I just took that sample workbook from my site and extended the sample data down to 350 rows. Then I ran the macro twice, once to create separate workbooks for each invoice (YES) and once to create sheets within the workbook (NO). Both completed all 350 for me.

Have you tried it both ways?

You can send your workbook to me to test if you wish, my contact info is on my site (use link below).
 
Upvote 0
I havent tried it both ways... having 321 workbooks is going not going to solve my issue. what Im trying to accomplish is:
we import data into a workbook, this data needs to be transferred to a template to be printed out and handed to employees. So i wanted to run a macro to create the worksheets, now they are copy and pasting manually, then printing each worksheet out. I would like to automate the copy and past process, and have them print out the whole workbook.

I will send you a copy of my workbook.. it will be a few minutes as I have to put some fake data into it.

Thank you for your help!!
 
Upvote 0
Also, I forgot to mention that my workstation has 4gb of memory and dual 2.93GHz processors.
 
Upvote 0
Thanks for the help. I got it working. I guess there was something wrong with the workbook... not sure.

But I copied and pasted the information in your example workbook and edited the code and it works great!!

I appreciate your help!!!!

-Brad
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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