Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Date does not update until worksheet change

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Date does not update until worksheet change

The SheetChange Event fires when you activate a different sheet within the
workbook. I think this is what you are wanting.

Put this code in worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1").Value = Date
End Sub
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Date does not update until worksheet change

Thank-you for answering Ryan.

The procedure you wrote works the way I wanted it to, but....

I get a run error at the end of the procedu " Method 'Value' of Object
'Range' failed."

It hilites this line of code in yellow: Range("A1").Value = Date

I don't understand why it's doing it. It seems to do what we want it to.
But when it's done running, it shows the above run error.

I have Excel 2007.

Amy

"Ryan H" wrote:

The SheetChange Event fires when you activate a different sheet within the
workbook. I think this is what you are wanting.

Put this code in worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1").Value = Date
End Sub
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Date does not update until worksheet change

Oops! You are right. Use this code instead.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub

The problem is when you change the value of Range A1 the Worksheet Change
Event fires again, and again, and again and again, resulting in an endless
loop which throws an error. This code will temporarly disable the event
while the data is changed.

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Thank-you for answering Ryan.

The procedure you wrote works the way I wanted it to, but....

I get a run error at the end of the procedu " Method 'Value' of Object
'Range' failed."

It hilites this line of code in yellow: Range("A1").Value = Date

I don't understand why it's doing it. It seems to do what we want it to.
But when it's done running, it shows the above run error.

I have Excel 2007.

Amy

"Ryan H" wrote:

The SheetChange Event fires when you activate a different sheet within the
workbook. I think this is what you are wanting.

Put this code in worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1").Value = Date
End Sub
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Date does not update until worksheet change



"Ryan H" wrote:

Oops! You are right. Use this code instead.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub

The problem is when you change the value of Range A1 the Worksheet Change
Event fires again, and again, and again and again, resulting in an endless
loop which throws an error. This code will temporarly disable the event
while the data is changed.

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Thank-you for answering Ryan.

The procedure you wrote works the way I wanted it to, but....

I get a run error at the end of the procedu " Method 'Value' of Object
'Range' failed."

It hilites this line of code in yellow: Range("A1").Value = Date

I don't understand why it's doing it. It seems to do what we want it to.
But when it's done running, it shows the above run error.

I have Excel 2007.

Amy

"Ryan H" wrote:

The SheetChange Event fires when you activate a different sheet within the
workbook. I think this is what you are wanting.

Put this code in worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1").Value = Date
End Sub
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Date does not update until worksheet change

Thanks Ryan. That fixed it. The routine runs great.
Amy

"Ryan H" wrote:

Oops! You are right. Use this code instead.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("A1").Value = Date
Application.EnableEvents = True
End Sub

The problem is when you change the value of Range A1 the Worksheet Change
Event fires again, and again, and again and again, resulting in an endless
loop which throws an error. This code will temporarly disable the event
while the data is changed.

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Thank-you for answering Ryan.

The procedure you wrote works the way I wanted it to, but....

I get a run error at the end of the procedu " Method 'Value' of Object
'Range' failed."

It hilites this line of code in yellow: Range("A1").Value = Date

I don't understand why it's doing it. It seems to do what we want it to.
But when it's done running, it shows the above run error.

I have Excel 2007.

Amy

"Ryan H" wrote:

The SheetChange Event fires when you activate a different sheet within the
workbook. I think this is what you are wanting.

Put this code in worksheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("A1").Value = Date
End Sub
--
Cheers,
Ryan


"spreadsheetlady" wrote:

Hi,
My work sheet has a date in cell: "A1".

I would like the date to update (only) if there is a change in the sheet.

I'm thinking of this to start:
Something like Private Sub Workbook_SheetChange(By Val Sh As Object, By Val_
Target As Excel.Range)

Thanks in advance,
Amy



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
Update Date Cell when any of target cells change DAKent Excel Worksheet Functions 2 September 11th 07 07:18 PM
change the name of a worksheet/update VBA code Dave F[_2_] Excel Discussion (Misc queries) 1 June 8th 07 09:22 PM
Update date field upon cell range change Carole O Excel Worksheet Functions 1 May 16th 07 05:04 AM
How to prevent file date change when no update made in Excel? John2348 Excel Discussion (Misc queries) 0 June 16th 06 04:27 PM
How do I get one worksheet to update when others change? Bdubs Excel Worksheet Functions 1 March 21st 06 06:40 PM


All times are GMT +1. The time now is 05:15 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"