jakester
Oct 25, 2010, 11:47 AM
Hey guys -
Ok, so I found some code on the Internet that I have been trying to tweak to my liking but I'm having some trouble. Here's what I am trying to do.
I want to create a worksheet for each day of a given month and name the worksheet for each respective day. The naming convention would work like: 10.01.10 Data, 10.02.10 Data, etc.
Also, I would like to create another set of worksheets that are named with the same date convention but with a different name: 10.01.10 Summary, 10.02.10 Summary.
Here's the code I found which helps me solve one part of my problem although the part that adds a new workbook is a little annoying because I would prefer that when I opened up a new workbook in Excel that the macro modify this open workbook instead of opening another workbook. But I'm unsure how to go about the same steps for creating the worksheets titled 10.01.10 Summary.
Here's the code:
Sub CreateNewBook()
Dim WS As Worksheet ', WB As Workbook
Dim MonthX As Date, Control As Variant, DaysInMonth As Byte, I As Byte, NewSheetCount As Byte, OldSheetCount As Byte
OldSheetCount = 1
Control = InputBox("Enter month in the form of mm/yyyy.", "Month Entry", Month(Date) & "/" & Year(Date))
If IsDate(Control) Then
MonthX = CDate(Control)
DaysInMonth = Day(DateSerial(Year(MonthX), Month(MonthX) + 1, 0))
Application.SheetsInNewWorkbook = DaysInMonth
'Set WB = Workbooks.Add
'Set WS = Worksheets.Add
I = 1
For Each WS In ActiveWorkbook.Worksheets
WS.Name = Month(MonthX) & " " & I
I = I + 1
Next
Else
MsgBox "Error while inputing start date."
End If
Application.SheetsInNewWorkbook = OldSheetCount
End Sub
Ok, so I found some code on the Internet that I have been trying to tweak to my liking but I'm having some trouble. Here's what I am trying to do.
I want to create a worksheet for each day of a given month and name the worksheet for each respective day. The naming convention would work like: 10.01.10 Data, 10.02.10 Data, etc.
Also, I would like to create another set of worksheets that are named with the same date convention but with a different name: 10.01.10 Summary, 10.02.10 Summary.
Here's the code I found which helps me solve one part of my problem although the part that adds a new workbook is a little annoying because I would prefer that when I opened up a new workbook in Excel that the macro modify this open workbook instead of opening another workbook. But I'm unsure how to go about the same steps for creating the worksheets titled 10.01.10 Summary.
Here's the code:
Sub CreateNewBook()
Dim WS As Worksheet ', WB As Workbook
Dim MonthX As Date, Control As Variant, DaysInMonth As Byte, I As Byte, NewSheetCount As Byte, OldSheetCount As Byte
OldSheetCount = 1
Control = InputBox("Enter month in the form of mm/yyyy.", "Month Entry", Month(Date) & "/" & Year(Date))
If IsDate(Control) Then
MonthX = CDate(Control)
DaysInMonth = Day(DateSerial(Year(MonthX), Month(MonthX) + 1, 0))
Application.SheetsInNewWorkbook = DaysInMonth
'Set WB = Workbooks.Add
'Set WS = Worksheets.Add
I = 1
For Each WS In ActiveWorkbook.Worksheets
WS.Name = Month(MonthX) & " " & I
I = I + 1
Next
Else
MsgBox "Error while inputing start date."
End If
Application.SheetsInNewWorkbook = OldSheetCount
End Sub