+ Reply to Thread
Results 1 to 7 of 7

VBA coding: macro to create a new sheet and have it named by data in a cell and the date

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    United States
    MS-Off Ver
    Office 2011
    Posts
    41

    VBA coding: macro to create a new sheet and have it named by data in a cell and the date

    The code I have right now will create a new sheet and insert the date, as the name of the sheet, but I'd like the code to do that and use data from a cell, as the name of the worksheet.

    here's the current code:

    Sub CheckAndAddSheetNameAsCurrentDate()

    Dim SheetName As String

    SheetName = Format(Date, "mm-dd-yy")

    On Error GoTo AddNew
    Sheets(SheetName).Activate
    Exit Sub

    AddNew:
    Sheets.Add , Worksheets(Worksheets.Count)
    ActiveSheet.Name = SheetName

    End Sub


    For bonus points, I'm trying to find out how to add a static date using a macro, that when a new worksheet template is opened it inserts the current date into this cell, and then NEVER changes it. I'm also looking to share a workbook, but lock a worksheet of that workbook. And I need to then create a worksheet of this workbook where all of this data is updated, but on a day by day basis and its clearly stated what day the data is from. (I have more requests, but I'm working this through.)

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    This would use the value in A1 as part of the new sheet's name.

    Please Login or Register  to view this content.
    Hope that helps.

  3. #3
    Registered User
    Join Date
    11-21-2012
    Location
    United States
    MS-Off Ver
    Office 2011
    Posts
    41

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    Thanks John! That worked perfectly!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    You're welcome. Glad to help out and thanks for the feedback.

  5. #5
    Registered User
    Join Date
    11-21-2012
    Location
    United States
    MS-Off Ver
    Office 2011
    Posts
    41

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    John, is it possible to insert another VBA code into this one and have both still work?

    This is the code I'm looking to add:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
    Application.EnableEvents = False
    If IsEmpty(.Value) Then
    .Offset(0, 1).ClearContents
    Else
    With .Offset(0, 1)
    .NumberFormat = "dd mmm yyyy hh:mm:ss"
    .Value = Now
    End With
    End If
    Application.EnableEvents = True
    End If
    End With
    End Sub

    And I would add that code and this one into one code...

    Sub CheckAndAddSheetNameAsCurrentDate()

    Dim SheetName As String

    SheetName = Range("C1").Value & " " & Format(Date, "mm-dd-yy")

    On Error GoTo AddNew
    Sheets(SheetName).Activate
    Exit Sub

    AddNew:
    Sheets.Add , Worksheets(Worksheets.Count)
    ActiveSheet.Name = SheetName

    End Sub

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    You could probably call it?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-21-2012
    Location
    United States
    MS-Off Ver
    Office 2011
    Posts
    41

    Re: VBA coding: macro to create a new sheet and have it named by data in a cell and the da

    Ok, I don't know why I'm trying to combine things I don't understand...lol...what I'm trying to do is make a date field that is static and is linked to the creation of a new cell. So, when I enter something into cell A4, that would make the cell I1 have the current date entered into it (in mm/dd/yy format)...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 02-09-2015, 01:21 PM
  2. Create new sheet named today's date and paste existing data into the sheet
    By kmao2004 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2014, 06:35 PM
  3. Search folders for named worksheets and create a master sheet of merged data
    By pmhancock10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-20-2013, 10:40 AM
  4. Coding help to transfer cell data to different sheet
    By DancingElvis in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-13-2013, 02:09 PM
  5. [SOLVED] Need Macro to Create New Worksheet Named After Currently Selected Cell
    By logabr01 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2013, 01:42 PM

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.6.0 RC 1