Change cell value upon save

lockarde

Board Regular
Joined
Oct 23, 2016
Messages
77
Good morning all,

I have a workbook that tracks current in progress and completed jobs for the month. I'd like two cells, C2 & D2, to update upon every save with date (C2) and time (D2), so everyone that has access can easily see when the workbook was updated. Any help is greatly appreciated!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How about
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  Sheets("Sheet1").Range("C2:D2").Value = Array(Date, Time)
End Sub
Change sheet name to suit.
This needs to go in the ThisWorkbook module
 
Upvote 0
Thanks for your quick reply Fluff! What you posted works great, but I'd like to run for every sheet in the workbook. I added a For Each loop, but it isn't running through every sheet, only updating the current worksheet. I'm thinking my syntax is off slightly. Here is what I have:
VBA Code:
Dim wSheet As Worksheet


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  For Each wSheet In Worksheets
    Range("C2:D2").Value = Array(Date, Time)
  Next wSheet
End Sub
 
Upvote 0
It needs to be
Rich (BB code):
wSheet.Range("C2:D2").Value = Array(Date, Time)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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