Create Worksheets based on a table

maxfli

New Member
Joined
Sep 14, 2010
Messages
26
I have a table that looks like this:
CompanyInvoice Amount 1 Amount 2 Amount 3 Amount 4 Amount 5PageLast Page
John Q Company3063615 $ 101 $ 200 $ 25 $ 25 $ 2511
Peter North Company3063616 $ 999 $ 877 $ 66 $ 66 $ 6611
Sam South Company3063617 $ 205 $ 180 $ 154 $ 164 $17417
Sam South Company3063617 $ 333 $ 195 $ 225 $ 375 $ 2227
Sam South Company3063617 $ 777 $ 987 $ 444 $ 200 $ 3337
Sam South Company3063617 $ 105 $ 111 $ 555 $ 344 $ 4447
Sam South Company3063617 $ 116 $ 137 $ 555 $ 65 $ 5557
Sam South Company3063617 $ 140 $ 245 $ 666 $ 242 $ 6667
Sam South Company3063617 $ 150 $ 333 $ 666 $ 255 $ 7777
Sam South Company3063618 $ 126 $ - $ - $ - $ -11
New York East Company3063619 $ 5,905 $ - $ - $ - $ -11

<tbody>
</tbody>

I have a COUNTIF formula and a MAX formula that will count the number of repeating invoice numbers. So the last 2 columns are the page number and the last page number. I need some kind of VB code that will do a FOR NEXT (?) loop in the case of invoice 3063617 it will copy an existing worksheet call ADDPAGE and rename it to PAGE 2, 3, 4 for each of pages 2 thru 7. I also need to populate amount field on each page. Page 1 is already created and assumed for all invoices.

Any Ideas?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I have a table that looks like this:
CompanyInvoice Amount 1 Amount 2 Amount 3 Amount 4 Amount 5PageLast Page
John Q Company3063615 $ 101 $ 200 $ 25 $ 25 $ 2511
Peter North Company3063616 $ 999 $ 877 $ 66 $ 66 $ 6611
Sam South Company3063617 $ 205 $ 180 $ 154 $ 164 $17417
Sam South Company3063617 $ 333 $ 195 $ 225 $ 375 $ 2227
Sam South Company3063617 $ 777 $ 987 $ 444 $ 200 $ 3337
Sam South Company3063617 $ 105 $ 111 $ 555 $ 344 $ 4447
Sam South Company3063617 $ 116 $ 137 $ 555 $ 65 $ 5557
Sam South Company3063617 $ 140 $ 245 $ 666 $ 242 $ 6667
Sam South Company3063617 $ 150 $ 333 $ 666 $ 255 $ 7777
JC Junk and Company3063618 $ 126 $ - $ - $ - $ -11
New York East Company3063619 $ 5,905 $ - $ - $ - $ -11

<tbody>
</tbody>

I have a COUNTIF formula and a MAX formula that will count the number of repeating invoice numbers. So the last 2 columns are the page number and the last page number. I need some kind of VB code that will do a FOR NEXT (?) loop in the case of invoice 3063617 it will copy an existing worksheet call ADDPAGE and rename it to PAGE 2, 3, 4 for each of pages 2 thru 7. I also need to populate amount field on each page. Page 1 is already created and assumed for all invoices.

Does anyone have any ideas on this question. I am probably not making myself clear. The Code needs to copy (Create) the ADDPage Worksheet for each page until the PAGE Column H2 = the LASTPAGE I2. I already have a routine that will print the invoice. In the case of the 7 page invoice when H2 = I2 it will call the print routine and then clean up the pages 2 - 7 and go on to the next record.

I appreciate any help!
 
Upvote 0
I have never done this myself but it looks like others have asked similar questions...

Google this... [ site:www.mrexcel.com "Create Worksheets" ].

There are 72 results on this forum. One of them surely would give you a direction to go.
 
Upvote 0
Yea I have been working on that exact search. The issue I have is not being able to incorporate is the idea of Copying (creating) the ADDPAGE Sheet using variables For the Current Page (Column H) to the Last Page (Column I). So essentially on invoice 3063617 I would add pages 2-7 and then call a print subroutine.
 
Upvote 0
Something like a Do While "Page" is <= "Last Page" or as you loop through invoice numbers run an If Then on page vs. last page; less than or equal to adds sheet, when equal add sheet and print.

Hope that helps,

Doug
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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