code not adding sheets

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
My code is not adding a sheet, and it looks like it should. It only has the one sheet called July. What have I done wrong?

VBA Code:
Sub AddYP()
Dim NewYP As String
    NewYP = Tracker.Cells(5, 4)
    YP.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = NewYP
    Call CreateWB(NewYP)
End Sub
Sub CreateWB(NewYP As String)
Dim wb1 As Workbook
    Workbooks.Add.SaveAs Filename:=ThisWorkbook.Path & "\Young People\" & NewYP, FileFormat:=52
    With Workbooks(NewYP)
        Sheets(1).Name = "July"
        Sheets.Add '.Name = "August"
    End With
End Sub
 
Your revamped code :​
VBA Code:
Sub CreateWB(NewYP As String)
        Dim V
    If IsEmpty([D5]) Then
        MsgBox "Please enter a name of the young person you want to add in the name field at D5"
        Exit Sub
    End If
        CheckFolderExists
        Workbooks.Add.SaveAs ThisWorkbook.Path & "\Young People\" & NewYP, 52
    For Each V In Split("7 8 9 10 11 12 1 2 3 4 5 6")
        Sheets.Add(, Sheets(Sheets.Count)).Name = MonthName(V)
    Next
End Sub
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks, but with that code, I get the months in the correct format but there is still a sheet1 as the first sheet. How do I get rid of it?
 
Upvote 0
VBA Code:
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
 
Upvote 0

Forum statistics

Threads
1,215,202
Messages
6,123,625
Members
449,109
Latest member
Sebas8956

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