+ Reply to Thread
Results 1 to 5 of 5

Thread: Automatically Create & Name New Worksheet Based On Cell Value (date)

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Automatically Create & Name New Worksheet Based On Cell Value (date)

    I have this figuered out, KIND OF, and need some help.

    I am trying to create a new worksheet for every cell value.

    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
    But this code - kind of works.

    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.

  2. #2
    Valued Forum Contributor
    Join Date
    12-14-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    986

    Re: Automatically Create & Name New Worksheet Based On Cell Value (date)

    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

  3. #3
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Automatically Create & Name New Worksheet Based On Cell Value (date)

    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!

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Automatically Create & Name New Worksheet Based On Cell Value (date)

    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

  5. #5
    Valued Forum Contributor
    Join Date
    12-14-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    986

    Re: Automatically Create & Name New Worksheet Based On Cell Value (date)

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0