Forum Discussion
Automatically name a new worksheet with a date sequence
- Jun 27, 2019
AnaPistol This macro checks if there alreay is a worksheet for the current month. If not it creates one. If there is, it selects it:
Sub AddMonthSheet() Dim sName As String Dim oSh As Worksheet sName = Format(Date, "yyyy-mmm") On Error Resume Next Set oSh = Worksheets(sName) If oSh Is Nothing Then Set oSh = Worksheets.Add End If oSh.Name = sName oSh.Activate End Sub
JKPieterse I am not looking for any reporting afterwards. We are looking at each sheet in the month it occurs. There will be too much data on one sheet to put all the months on one sheet. But thank you for your suggestion.
AnaPistol This macro checks if there alreay is a worksheet for the current month. If not it creates one. If there is, it selects it:
Sub AddMonthSheet() Dim sName As String Dim oSh As Worksheet sName = Format(Date, "yyyy-mmm") On Error Resume Next Set oSh = Worksheets(sName) If oSh Is Nothing Then Set oSh = Worksheets.Add End If oSh.Name = sName oSh.Activate End Sub
- AnaPistolJul 05, 2019Copper Contributor
JKPieterse Thank you! This worked exactly how i needed it to!
- TwifooJul 05, 2019Silver ContributorSheer inadvertence, honest mistake, or excusable negligence indubitably caused you to confirm your thanks to JKPieterse as the best response! Please be circumspect next time. I also call the attention of EricStarker to perhaps do something to avert a similar occurrence.
- EricStarkerJul 05, 2019Former Employee
Twifoo This is a very large site with a number of different communities, so our team does not have time to police best responses, which is voluntary on the part of users (please don't tag me on these).
If you have an overall suggestion for the site, feel free to submit it in our Community Ideas space.