MrExcel's Learn Excel #730 - Insert Worksheets

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Feb 12, 2009.
J.B. needs to create a new worksheet for every customer listed on the summary worksheet. He asks if there is an Insert Worksheets command. While there isn't, you can create one with a few lines of VBA code. Episode 730 shows you how.

This blog is the video podcast companion to the book, Learn Excel 97-2007 from MrExcel. Download a new two minute video every workday to learn one of the 377 tips from the book!
maxresdefault.jpg


Transcript of the video:
Hey! Welcome back to the MrExcel netcast.
I'm Bill Jelen.
Today, we have a question from JB.
JB says, "I have a worksheet with a whole series of customers and I need to create a worksheet for every single customer in the list." He says, "There's hundreds of them.
Is there a way that I could just select a range and you know, say create tabs or something like that." Well, unfortunately there isn't but we're Going to do this with a little bit of VBA, today.
But before I launch into the VBA, I want to do a little bit of testing.
I was thinking about the worksheets dot add command and what we're going to do here, is we're going to take a look at both Excel and the VBA window at the same time.
So, we can see the VBA window here and you'll be able to see the sheet tabs.
If I just ran worksheets dot add, a couple of times.
So, step through this by hitting [ F8 ], you see that when we add the first worksheet is automatically added to the left of the current worksheet.
So, if we just did worksheets dot add, it would keep adding things to the left and as we think about JB's data, he probably has the first customer alphabetically at the top.
So, I really want to be adding those worksheets to the end and so what we're going to do here instead of just worksheets add, we're going to say after and rather than trying to remember what the last worksheet in the workbook, is I'm going to say worksheets and then specify which worksheet by position.
So, that's simply worksheets count.
So, in this case right now, we have three worksheets.
If I say worksheets dot count that's saying number three and I'll say after the third worksheet.
So, now let's run this a few times and you'll notice down here and the new worksheet sheet twelve will be added after sheet one.
So, that's the trick, in order to be able to add these worksheets.
Now, the other thing you'll notice is that after we add the worksheet.
The new sheet becomes the active sheet.
So in JB's case what we're going to do is we're basically and say...
For each cell in selection.
We're going to add a new worksheet and then, we can rename the active sheet dot name equals cell value and then next cell.
Alright! So, let's go back to the original worksheet, we'll delete all the extra worksheets.
So, we just start out with just sheet one.
I'll select all the customers and then, we'll run our macro, test macro, click [ run ] and sure enough there had added 60 new worksheets in order and named each worksheet with the name from the cell.
Simple a little bit of code, just a few lines of code, have to do some testing there to get worksheets dot add to work the way that we wanted it to.
To add the worksheets to the end instead of always adding it to the left of the active cell.
Thanks to JB for sending in that question and thanks to you for stopping by.
We'll see you next time for another netcast from MrExcel.
 

Forum statistics

Threads
1,224,946
Messages
6,181,938
Members
453,074
Latest member
JefersonKollet

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