Naming a new sheet using the NOW formula

JJbug

Board Regular
Joined
Mar 16, 2012
Messages
68
Hello,

Your local Novice here. I am trying to create a log for changes made to a master data workbook. So far I am having some issue with naming the new sheet created by the macro, see code below.

Sub ChangeLog()
ActiveCell.Select
ActiveCell.FormulaR1C1 = "Change Submission"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=NOW()"
ActiveCell.Offset(1, -1).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Offset(1, 0).Range("A1").Select

sheet_name_to_create = Sheet1.Range("C4").Value
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(sheet_name_to_create) Then
MsgBox "This sheet already exists!"
Exit Sub
End If


Next



Sheets.Add After:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = sheet_name_to_create

End Sub


_______________________________________


This is the begining of the code, next it will open master file and move a copy of all the changed data to the new sheet which should be named as the date of the change submission.

Please let me know if you need clarification on any details.

Thank you again for all of your help you all are the best.
 
Yes you are right, I wanted to use the Date and Time as the sheet name which is working fine or well close.
Additionally I am logging each date and time the action is run. This is being logged on a tab called "Change Log", the following is an example of what the Change Log will look like. As you can see the NOW function will not work unless I use a paste special after each entry. Also I will try to add a Version # to each entry.

This is only a small piece of the larger puzzle I am trying to assemble. In the end this macro will be added to a set of master files to log and save any changes made for easier review and audit.

BUTTON

Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>
Change Submission</SPAN>#NAME?</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL></COLGROUP>
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I thought you only wanted the DATE in the sheet name, so I used the Date function.

Try changing that to NOW
sheet_name_to_create = Format(Now, "mmm-d-yyyy-hh-mm")

Yes you are right, I wanted to use the Date and Time as the sheet name which is working fine or well close.
Additionally I am logging each date and time the action is run. This is being logged on a tab called "Change Log", the following is an example of what the Change Log will look like. As you can see the NOW function will not work unless I use a paste special after each entry. Also I will try to add a Version # to each entry.

This is only a small piece of the larger puzzle I am trying to assemble. In the end this macro will be added to a set of master files to log and save any changes made for easier review and audit.

BUTTON

Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>1/8/2014 8:10</SPAN>
Change Submission</SPAN>
Change Submission</SPAN>#NAME?</SPAN>

<TBODY>
</TBODY>
 
Upvote 0
Try

Code:
Sub Change_Log()
Dim NewName As String, ws As Worksheet
NewName = Format(Now, "mmm-d-yyyy hh.mm")
For Each ws In Worksheets
    If ws.Name = NewName Then
        MsgBox "Sheet Already Exists"
        Exit Sub
    End If
Next ws
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = NewName
With Sheets("Change Log").Range("A" & Rows.Count).End(xlUp)
    .Offset(1, 0).Value = "Change Submission"
    .Offset(1, 1).Value = Now
    .Offset(1, 1).NumberFormat = "m/d/yyyy h:mm"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,792
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top