Macro for putting last modified date in cell A1

jamdur1

New Member
Joined
Aug 2, 2012
Messages
8
I need a formula or macro to put in the last modified date in cell A1 for one sheet in my workbook. I've searched and found a few formulas but they don't seem to be working. Any ideas?
 
Environ("Username") will return the name of the person logged in

Code:
    With Range("B1")
        .Value = Environ("Username")
    End With

Environ can return any of the variables you see when using SET from the command prompt

I believe that gets me the last person who saved the file, rather than the last person to edit a specific sheet; is there any way to do it by sheet rather than by the whole file?
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Environ("Username") will return the name of the person logged in when that function is executed. If it is during the workbook save event, then it will record who was logged in when the workbook was saved. If it is executed during a Worksheet_Change event then it will record the user at the time a change was made.

It sounds as if you want to keep close track of all changes to this worksheet. Code can be written to track what was changed by who and when for each cell on the worksheet by writing to another worksheet or workbook. This will cause extra load on the system.

This post shows an example to track all changes of a single cell on any worksheet: http://www.mrexcel.com/forum/excel-questions/274711-find-out-who-last-modified-excel-file.html It could be modified to track any changes on a specific worksheet as well.

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    'If any cell on a worksheet is changed manually or progrmatically, update date/time in cell A1 of tha worksheet
    ' and the name of the person logged in when that change was made
    Application.EnableEvents = False
    With Range("A1")
        .Value = Now()
        .NumberFormat = "mm/dd/yyyy hh:mm:ss"
    End With
    With Range("B1")
        .Value = Environ("Username")
    End With
    Application.EnableEvents = True
End Sub
 
Upvote 0
Environ("Username") will return the name of the person logged in when that function is executed. If it is during the workbook save event, then it will record who was logged in when the workbook was saved. If it is executed during a Worksheet_Change event then it will record the user at the time a change was made.

It sounds as if you want to keep close track of all changes to this worksheet. Code can be written to track what was changed by who and when for each cell on the worksheet by writing to another worksheet or workbook. This will cause extra load on the system.

This post shows an example to track all changes of a single cell on any worksheet: http://www.mrexcel.com/forum/excel-questions/274711-find-out-who-last-modified-excel-file.html It could be modified to track any changes on a specific worksheet as well.

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    'If any cell on a worksheet is changed manually or progrmatically, update date/time in cell A1 of tha worksheet
    ' and the name of the person logged in when that change was made
    Application.EnableEvents = False
    With Range("A1")
        .Value = Now()
        .NumberFormat = "mm/dd/yyyy hh:mm:ss"
    End With
    With Range("B1")
        .Value = Environ("Username")
    End With
    Application.EnableEvents = True
End Sub

This works great! Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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