Link to home
Start Free TrialLog in
Avatar of gisvpn
gisvpnFlag for United States of America

asked on

Create new Worksheets from another worksheets (VBA)

I have a worksheet which is a template that I would like to use for other worksheets (via VBA) - hope that’s makes sense, but I will try to explain a little more.

I have two worksheets in my spreadsheet. One is called data and the other called template. The data worksheet has a load of data which details some projects and their status and the template is a formatted worksheet (to look nice) that I would like to populate each row listed on the data worksheet with on its down tab.

In plain English this is what I would like to do :

1. Delete any worksheets (existing) which are not called data or template
2. Create a new tab (with the new worksheet being a copy of the worksheet called template) for each row in the data worksheet and name it with the value in column AH for that row.
3. Copy data from the data spreadsheet for that project into the worksheet created for that project (based off of the value in cell AH (which is the project name) e.g. copy value in column Z for that row in data worksheet into C21 of the worksheet of the worksheet created for that project.. etc.. there will be about 30 values copied across.

If someone could give me a head start on the basics above that would be great!.

Thanks for any help in advance.
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

A sample file showing some input as well as expected output based on that input would be helpful :)
Avatar of gisvpn

ASKER

hey matthewspatrick - Hope the attached helps.

In the example attached I would be looking for each row on the Data worksheet have a new tab created named by the name of the Sponsor listed in column B of the data worksheet.

Using the template in the template worksheet I would like the contents of the each new worksheet to be  a copy of the template worksheet and have the data populated into it with the information from the data worksheet for that row.

I have created an example worksheet in the spreadsheet attached called Peter James  which shows what I am trying to create ;)

Dont worry about the colour of the red cell (it just has a conditional formatting condition on it - copied from the template worksheet.

Hope this is clearer, however If I have not made myself clear please just ask!

Thanks,

GISVPN
No attachment :)
Avatar of gisvpn

ASKER

attached here ;)
Book2.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gisvpn

ASKER

Hi matthewspatrick,

This is a great example, thank you for the code.

Could I ask for one addition. In excel the max length of a worksheet name is 31 characters. How can I add when it names the sheet (.Name = arr(r, 1)) to only use the first 31 characters of  r,1 value so it can name the sheet successfully in all cases ;)?

Thanks,

GISVPN
Replace:

           .Name = arr(r, 1)

with

           Left(.Name = arr(r, 1), 31)
Avatar of gisvpn

ASKER

hey matthewspatrick,

I get syntax error ;)?
.Name = Left(arr(r, 1), 31)