I have this figuered out, KIND OF, and need some help.
I am trying to create a new worksheet for every cell value.
But this code - kind of works.Sub AddMonthlySheets() Dim mMonth As Range For Each mMonth In Sheets(1).Range("A1:A12") ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count) ActiveSheet.Name = mMonth Next End Sub
If you look at my attached file NewWorksheetTEST.xlsm , it works when the data is in 'January' format. But I need my data to be in 'mmm-yyyy' format (Jan-2012). Once I chnage the format, it doesnt work.
I think its because January is text format and Jan-2012 is a date format, but I dont know how to update my code to accommodate the date format.
Any suggestions would be greatly appreciated.
Thanks in advance.
Last edited by clemsoncooz; 12-30-2011 at 11:48 AM.
I revised your code a little bit
Sub AddMonthlySheets() Application.ScreenUpdating = False Dim mMonth As Range For Each mMonth In Sheets(1).Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row) ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count) ActiveSheet.Name = Left(mMonth, 3) & "-2011" Next Worksheets("Sheet1").Select Application.ScreenUpdating = True End Sub
To thank someone who has helped you, click on the star icon below their name.
I hate reading
Portfolio
I need a job.I am young and incompetent
Hello JieJenn. Thank you very much for taking the time to look at this and offer a solution. I appreciate that.
But yours also "kind of" works - not quite what I am looking for.
I'm looking for whatever the name is (and format) to show on the worksheet name. So if I type "1/1/12" into A1, but have the cell format to be "mmm-yyyy" (meaning Jan-2012 shows in A1), then the worksheet name would be Jan-2012. More so, if I typed 5/6/15, and the cell format shows to be May-2015, I want the worksheet name to be "May-2015."
Does this make more sense?
Thanks!
Maybe found the solution, If any one cares, I think this might be what I was after in the first place.
Sub AddMonthlySheets() Dim mMonth As Range For Each mMonth In Sheets(1).Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row) If mMonth.Value = "" Then Exit For 'this exits the loop when you have a blank cell ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count) ActiveSheet.Name = Application.WorksheetFunction.Text(mMonth.Value, mMonth.NumberFormat) Next End Sub
The values in your workbook in Column A are "text" despite that the formatting was custom. Date formatting does not work with text, and that was where my assumption coming from.
To thank someone who has helped you, click on the star icon below their name.
I hate reading
Portfolio
I need a job.I am young and incompetent
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks