Hello Everyone! I have a VBA issue I can not beat and need the experts.
On my "Project Tracker" tab I have a list of names in starting in cell D7 and going down. Names can be duplicated
Currently I have a macro that when clicked, it will look through this range of data, find the unique values, and will add in a tab and rename each tab the unique name.
What I can't seem to do is instead of adding a blank sheet for each unique name, I Need to be able to copy my "Blank Client" tab have that added for each unique name.
In other words, button is clicked, sheet "Blank Client" is copied and pasted to a tab that is added and named for each unique name.
My current Macro is below..... Please make any changes directly in it. I have other little things like add all new sheets at the end, sort names, etc
On my "Project Tracker" tab I have a list of names in starting in cell D7 and going down. Names can be duplicated
Currently I have a macro that when clicked, it will look through this range of data, find the unique values, and will add in a tab and rename each tab the unique name.
What I can't seem to do is instead of adding a blank sheet for each unique name, I Need to be able to copy my "Blank Client" tab have that added for each unique name.
In other words, button is clicked, sheet "Blank Client" is copied and pasted to a tab that is added and named for each unique name.
My current Macro is below..... Please make any changes directly in it. I have other little things like add all new sheets at the end, sort names, etc
VBA Code:
Sub CreateWorksheets(Names_Of_Sheets As Range)
Sheets("Project Tracker").Select
ActiveWorkbook.Worksheets("Project Tracker").ListObjects("ProjectTrackerTable") _
.sort.SortFields.Clear
ActiveWorkbook.Worksheets("Project Tracker").ListObjects("ProjectTrackerTable") _
.sort.SortFields.Add2 Key:=Range( _
"ProjectTrackerTable[[#All],[Customer Name]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Project Tracker").ListObjects( _
"ProjectTrackerTable").sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Dim No_Of_Sheets_to_be_Added As Integer
Dim Sheet_Name As String
Dim i As Integer
Sheets.Add after:=Sheets(Sheets.Count)
No_Of_Sheets_to_be_Added = Names_Of_Sheets.Rows.Count
For i = 1 To No_Of_Sheets_to_be_Added
Sheet_Name = Names_Of_Sheets.Cells(i, 1).Value
'Only add sheet if it doesn't exist already and the name is longer than zero characters
If (Sheet_Exists(Sheet_Name) = False) And (Sheet_Name <> "") Then
Worksheets.Add().Name = Sheet_Name
End If
Next i
Sheets(Sheets.Count).Select
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
Private Sub CommandButton2_Click()
Call CreateWorksheets(Sheets("Project Tracker").Range("D7:D100"))
End Sub
Last edited by a moderator: