Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
RJD RJD is offline
external usenet poster
 
Posts: 6
Default Update date & time in a cell only when worksheet is changed

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Update date & time in a cell only when worksheet is changed

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.

  #3   Report Post  
Posted to microsoft.public.excel.misc
RJD RJD is offline
external usenet poster
 
Posts: 6
Default Update date & time in a cell only when worksheet is changed

Mike,

Thanks for your reply to my question. I'm new to "writing code" to
accomplish something like this Excel. I followed your instructions but may
have missed something obvious to a more experience user.

I pasted the code you provided in the window as you instructed, and changed
("A1") to ("G1") so the date & time would be in the G1 cell of my first
worksheet. I selected ALT+F11 again to go back to the worksheet and nothing
appears in G1 of worksheet 1. I'm sure your code is right and it's something
I'm doing wrong.

Since I want the date & time in each worksheet, wouldn't I select the
specific sheet instead of "ThisWorkbook" and paste the code?

I may need a little more detail in how to use VB editor this first time to
get this right.

Thanks,

RJD


"Mike H" wrote:

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Update date & time in a cell only when worksheet is changed

RJD

After returning to Excel from VBE you must select any cell except G1 on any
sheet.

Make a change and ENTER. The date/time will appear in G1.

Having the code in Thisworkbook saves you the duplicating the code in each
worksheet.

If you just wanted it for one sheet you would change the event type to

Private Sub Worksheet_Change(ByVal Target As Range)

and paste it into the sheet module.

Mike has steered you correctly because you wanted it for every sheet in the
workbook.


Gord Dibben MS Excel MVP


On Wed, 16 Dec 2009 07:32:01 -0800, RJD
wrote:

Mike,

Thanks for your reply to my question. I'm new to "writing code" to
accomplish something like this Excel. I followed your instructions but may
have missed something obvious to a more experience user.

I pasted the code you provided in the window as you instructed, and changed
("A1") to ("G1") so the date & time would be in the G1 cell of my first
worksheet. I selected ALT+F11 again to go back to the worksheet and nothing
appears in G1 of worksheet 1. I'm sure your code is right and it's something
I'm doing wrong.

Since I want the date & time in each worksheet, wouldn't I select the
specific sheet instead of "ThisWorkbook" and paste the code?

I may need a little more detail in how to use VB editor this first time to
get this right.

Thanks,

RJD


"Mike H" wrote:

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.


  #5   Report Post  
Posted to microsoft.public.excel.misc
RJD RJD is offline
external usenet poster
 
Posts: 6
Default Update date & time in a cell only when worksheet is changed

Hi,
It's still not working. I pasted Mike's code in the "ThisWorkbook" VB editor
and changed ("A1") to ("H1"). I went back to the Excel file and wrote "test"
in an empty cell (not H1) of Worksheet 1 and hit "Enter." Nothing appears in
H1.

Does it matter how the cell is formatted? Right now its set for "General"
formatting.

I appreciate your help and patience.

RJD


"Gord Dibben" wrote:

RJD

After returning to Excel from VBE you must select any cell except G1 on any
sheet.

Make a change and ENTER. The date/time will appear in G1.

Having the code in Thisworkbook saves you the duplicating the code in each
worksheet.

If you just wanted it for one sheet you would change the event type to

Private Sub Worksheet_Change(ByVal Target As Range)

and paste it into the sheet module.

Mike has steered you correctly because you wanted it for every sheet in the
workbook.


Gord Dibben MS Excel MVP


On Wed, 16 Dec 2009 07:32:01 -0800, RJD
wrote:

Mike,

Thanks for your reply to my question. I'm new to "writing code" to
accomplish something like this Excel. I followed your instructions but may
have missed something obvious to a more experience user.

I pasted the code you provided in the window as you instructed, and changed
("A1") to ("G1") so the date & time would be in the G1 cell of my first
worksheet. I selected ALT+F11 again to go back to the worksheet and nothing
appears in G1 of worksheet 1. I'm sure your code is right and it's something
I'm doing wrong.

Since I want the date & time in each worksheet, wouldn't I select the
specific sheet instead of "ThisWorkbook" and paste the code?

I may need a little more detail in how to use VB editor this first time to
get this right.

Thanks,

RJD


"Mike H" wrote:

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.


.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Update date & time in a cell only when worksheet is changed

Formatting does not matter.

Sounds like maybe you got events disabled and not re-enabled.

Mike did not add any error trapping to re-enable events in case of error,
although I cannot see much chance of an error occuring.

First go to VBE and ViewImmediate Window

Copy the follwing into the window Application.EnableEvents = True

Hit enter.

Paste this amended code into Thisworkbook module........delete the original.

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
On Error GoTo endit
Application.EnableEvents = False
ActiveSheet.Range("H1").Value = Now
endit:
Application.EnableEvents = True
End Sub

Alt + q to return to a sheet. Try entering data in a cell.


Gord



On Wed, 16 Dec 2009 14:01:01 -0800, RJD
wrote:

Hi,
It's still not working. I pasted Mike's code in the "ThisWorkbook" VB editor
and changed ("A1") to ("H1"). I went back to the Excel file and wrote "test"
in an empty cell (not H1) of Worksheet 1 and hit "Enter." Nothing appears in
H1.

Does it matter how the cell is formatted? Right now its set for "General"
formatting.

I appreciate your help and patience.

RJD


"Gord Dibben" wrote:

RJD

After returning to Excel from VBE you must select any cell except G1 on any
sheet.

Make a change and ENTER. The date/time will appear in G1.

Having the code in Thisworkbook saves you the duplicating the code in each
worksheet.

If you just wanted it for one sheet you would change the event type to

Private Sub Worksheet_Change(ByVal Target As Range)

and paste it into the sheet module.

Mike has steered you correctly because you wanted it for every sheet in the
workbook.


Gord Dibben MS Excel MVP


On Wed, 16 Dec 2009 07:32:01 -0800, RJD
wrote:

Mike,

Thanks for your reply to my question. I'm new to "writing code" to
accomplish something like this Excel. I followed your instructions but may
have missed something obvious to a more experience user.

I pasted the code you provided in the window as you instructed, and changed
("A1") to ("G1") so the date & time would be in the G1 cell of my first
worksheet. I selected ALT+F11 again to go back to the worksheet and nothing
appears in G1 of worksheet 1. I'm sure your code is right and it's something
I'm doing wrong.

Since I want the date & time in each worksheet, wouldn't I select the
specific sheet instead of "ThisWorkbook" and paste the code?

I may need a little more detail in how to use VB editor this first time to
get this right.

Thanks,

RJD


"Mike H" wrote:

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.


.


  #7   Report Post  
Posted to microsoft.public.excel.misc
RJD RJD is offline
external usenet poster
 
Posts: 6
Default Update date & time in a cell only when worksheet is changed

I'm back with another question. Sorry it took so long to try the last
suggestion.

I followed each step below. When I pasted the information in the "Immediate
Window" screen and hit "Enter," a dialog box popped up that said "The macros
in this window are disabled. Please refer to on-line Help for..."

I did a little research on how to disable macros, but in doing so read that
there is some danger when macros are enabled. I tried some of the options
available, like keeping macros disabled and notify me when one is present.
None of those worked. I finally chose to enable macros and now the script
provided below works exactly like I requested help for (thanks, by the way).

My question is, what risk am I running having macros enabled in my copy of
Excel? I assume now any Excel file I open with a macro will open without
warning. Is there a way I can run the file I just added the script to, with
marcos disabled, "but notify?"

RD

"Gord Dibben" wrote:

Formatting does not matter.

Sounds like maybe you got events disabled and not re-enabled.

Mike did not add any error trapping to re-enable events in case of error,
although I cannot see much chance of an error occuring.

First go to VBE and ViewImmediate Window

Copy the follwing into the window Application.EnableEvents = True

Hit enter.

Paste this amended code into Thisworkbook module........delete the original.

Private Sub Workbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
On Error GoTo endit
Application.EnableEvents = False
ActiveSheet.Range("H1").Value = Now
endit:
Application.EnableEvents = True
End Sub

Alt + q to return to a sheet. Try entering data in a cell.


Gord



On Wed, 16 Dec 2009 14:01:01 -0800, RJD
wrote:

Hi,
It's still not working. I pasted Mike's code in the "ThisWorkbook" VB editor
and changed ("A1") to ("H1"). I went back to the Excel file and wrote "test"
in an empty cell (not H1) of Worksheet 1 and hit "Enter." Nothing appears in
H1.

Does it matter how the cell is formatted? Right now its set for "General"
formatting.

I appreciate your help and patience.

RJD


"Gord Dibben" wrote:

RJD

After returning to Excel from VBE you must select any cell except G1 on any
sheet.

Make a change and ENTER. The date/time will appear in G1.

Having the code in Thisworkbook saves you the duplicating the code in each
worksheet.

If you just wanted it for one sheet you would change the event type to

Private Sub Worksheet_Change(ByVal Target As Range)

and paste it into the sheet module.

Mike has steered you correctly because you wanted it for every sheet in the
workbook.


Gord Dibben MS Excel MVP


On Wed, 16 Dec 2009 07:32:01 -0800, RJD
wrote:

Mike,

Thanks for your reply to my question. I'm new to "writing code" to
accomplish something like this Excel. I followed your instructions but may
have missed something obvious to a more experience user.

I pasted the code you provided in the window as you instructed, and changed
("A1") to ("G1") so the date & time would be in the G1 cell of my first
worksheet. I selected ALT+F11 again to go back to the worksheet and nothing
appears in G1 of worksheet 1. I'm sure your code is right and it's something
I'm doing wrong.

Since I want the date & time in each worksheet, wouldn't I select the
specific sheet instead of "ThisWorkbook" and paste the code?

I may need a little more detail in how to use VB editor this first time to
get this right.

Thanks,

RJD


"Mike H" wrote:

Hi,

You need code for that. ALT+F11 to open VB editor. Double click
'ThisWorkbook and paste the code below in on the right. Change the cell to
the one you want

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
ActiveSheet.Range("A1").Value = Now
Application.EnableEvents = True
End Sub

Mike

"RJD" wrote:

I have a workbook with multiple worksheets. I'd like to have the time & date
in a cell in each worksheet update only when information in that worksheet is
changed. I don't change each worksheet each time I use the workbook. I tried
=NOW(), but it changes the time and date in each worksheet.

.


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
STORE THE DATE & TIME THE VALUE HAS CHANGED IN A CELL Asoka Walpitagama - Brandix College IT Excel Discussion (Misc queries) 1 January 29th 09 12:12 PM
can i see the date the last time a cell was changed? JohnNuTek New Users to Excel 3 May 10th 07 11:32 PM
Can excel update date when document last changed? Nic Excel Discussion (Misc queries) 1 July 26th 06 07:44 PM
Update Link When Worksheet Title is Changed yvonne a via OfficeKB.com Links and Linking in Excel 1 July 15th 05 11:27 PM
How do you continuously update time and date in an Excel cell? engine99 Excel Worksheet Functions 7 February 21st 05 02:20 AM


All times are GMT +1. The time now is 09:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"