Creating worksheets from a database

EXCELlant

New Member
Joined
May 28, 2009
Messages
29
I have a contract in an excel worksheet and a list of 50 names in a database (in Column A).

is there a way to duplicate the contract to make 50 tabs with each contract having the persons name from the database?
e.g Contract 1; Mr Smith
Contract 2; Mr Brown

the name need to populate in cell D4 of the contract.

Any help or suggestions would be great.

Thanks!!!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What's the sheet name of your database sheet and is the contract another sheet? If so what's its name?
 
Upvote 0
Hi Scott,

There are two seperate sheets 'Database' with the list of 50 names and currently one template of the contract labelled 'Master'.

i was thinking of the VBA creating duplicates of the 'Master' each with it own unique name from the 'Database'.

What do you think?

Thanks for your help
 
Upvote 0
I've assumed your list of names starts in Row 2 on the database page (if not adjust the value of 'x') and have left it dynamic in case the list size changes from 50.

Code:
Sub CreateContracts()

Dim dbSh As Worksheet, shCnt As Integer
Dim tSh As Worksheet
Dim cSh As Worksheet

Set dbSh = ThisWorkbook.Sheets("Database")
Set tSh = ThisWorkbook.Sheets("Master")

x = 2
Do
    If dbSh.Cells(x, 1) = "" Then Exit Do
    shCnt = ThisWorkbook.Sheets.Count
    tSh.Copy After:=Sheets(shCnt)
    Set cSh = ThisWorkbook.Sheets(shCnt + 1)
    cSh.Name = "Contract; " & dbSh.Cells(x, 1)
    cSh.Cells(4, 4) = dbSh.Cells(x, 1)
    x = x + 1
Loop

End Sub
 
Upvote 0
SUPERB! thats exactly what i needed!

im trying to get more familiar with vba but unfortunatly dont understand this coding.

thanks for all of your help though Scott.
 
Upvote 0
You're welcome.

Depending on your current level of knowledge playing around with the macro recorder is a good place to start. Just keep in mind it is a deeply flawed tool that produces inefficient code and won't teach you anything about looping but it will give you insight in the Excel Object Model and its properties, events etc.
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,306
Members
449,218
Latest member
Excel Master

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