Macro to create excel sheets dynamically based on values of one sheet

Sub Macro2()
Dim wsNew As Worksheet
Dim wsMaster As Worksheet
Dim x As Long

Dim cell As Range
'Sheet2 will be copied as new sheet and renamed with data in Sheet1 columns A and B
Set wsMaster = ActiveWorkbook.Sheets("Sheet2")
x = 1

Do While Not IsEmpty(Sheet1.Cells(x, 1).Value)
wsMaster.Copy Before:=wsMaster

Sheet_name_to_create = Sheet1.Cells(x, 1).Value & "-" & Sheet1.Cells(x, 2).Value

Set wsNew = ActiveWorkbook.ActiveSheet
wsNew.Name = Sheet_name_to_create

x = x + 1
Loop

End Sub

This creates sheets with name of col A and B in sheet 1 and copy the sheet2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s