PC Review


Reply
Thread Tools Rate Thread

Date does not update until worksheet change

 
 
spreadsheetlady
Guest
Posts: n/a
 
      4th Jan 2010
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 With Quote
 
 
 
 
Ryan H
Guest
Posts: n/a
 
      4th Jan 2010
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 With Quote
 
spreadsheetlady
Guest
Posts: n/a
 
      4th Jan 2010
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 procedure: " 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 With Quote
 
Ryan H
Guest
Posts: n/a
 
      4th Jan 2010
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 procedure: " 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 With Quote
 
spreadsheetlady
Guest
Posts: n/a
 
      4th Jan 2010


"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 procedure: " 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 With Quote
 
spreadsheetlady
Guest
Posts: n/a
 
      4th Jan 2010
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 procedure: " 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 change date in 1 cell/worksheet so it changes in all workshe Mjd0985 Microsoft Excel Misc 2 17th Feb 2010 05:28 PM
how do i get the date and time if a change is done in a worksheet srini Microsoft Excel Misc 2 16th Feb 2010 02:41 AM
How do I set up a date to update individually on each worksheet? =?Utf-8?B?Y2hlZmJlYXZyZGVl?= Microsoft Excel Programming 1 28th Aug 2006 04:43 PM
How do I get one worksheet to update when others change? =?Utf-8?B?QmR1YnM=?= Microsoft Excel Worksheet Functions 1 21st Mar 2006 06:40 PM
Worksheet Revision Date update only once in the same day mikeburg Microsoft Excel Programming 8 18th Aug 2005 09:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 AM.