dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have code that creates a workbook if it doesn't exist. I then want to format the worksheets but with my code I get the error, object doesn't support this property or method. The line that is highlighted is in SetupSheets:
VBA Code:
For Each Worksheet In ThisWorkbook
VBA Code:
Sub AddYP()
Application.DisplayAlerts = False
Dim newyp As String
newyp = Tracker.Cells(5, 4)
YP.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = newyp
Call CreateWB(newyp)
ThisWorkbook.Names.Add Name:="tblYPNames", _
RefersTo:=Range("tblYPNames").Resize(Range("tblYPNames").Rows.Count + 1)
Tracker.cboYP.ListFillRange = "tblYPNames"
Tracker.cboDeleteYP.ListFillRange = "tblYPNames"
Application.DisplayAlerts = True
End Sub
Sub CreateWB(newyp As String)
Dim V
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
Call SetupSheets
Sheets("sheet1").Delete
ActiveWorkbook.Close savechanges:=True
Tracker.Cells(5, 4).Clear
End Sub
Sub SetupSheets()
Dim Worksheet As Worksheet
For Each Worksheet In ThisWorkbook
Range("A1").Value = "Date"
Range("A2").Value = "GL Code"
Range("A3").Value = "Supplier"
Range("A4").Value = "Amount"
Range("A5").Value = "Comments"
With Rows(1)
.Font.Bold = True
.Interior.ColorIndex = 15
End With
Next
End Sub