+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Timestamp not calculating when referencing a calculated (IF) cell

  1. #1
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Timestamp not calculating when referencing a calculated (IF) cell

    I have read dozens of posts regarding McGimpsey solution to the timestamp problem (http://www.mcgimpsey.com/excel/timestamp.html)

    His VBA solution works perfectly if you type a value in the reference cell.

    However if the reference cell contains a formula then nothing happens.

    eg:

    Col B: =if(A1>50,1,0) etc . .
    Col C: Uses McGimpsey VBA code to update C1 when A1>50

    The Col C timestamp only works if I type "1" into Col B. Nothing happens otherwise.

    My actual problem is much more complex than shown above - but I hope this illustrates the point.

    Any ideas how to overcome this problem.
    Last edited by gregcarroll; 02-07-2012 at 04:43 PM.

  2. #2
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    If the change is the result of a formula then take a look at the calculate event
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  3. #3
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Hi Jeff,

    Could you please elaborate so I dont have to search through a few dozen more forums. I am new to VBA in Excel.

    Greg

  4. #4
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Hi Greg,

    Maybe this will help

    http://dmcritchie.mvps.org/excel/event.htm#calculate

    From Excel help
    Worksheet.Calculate Event
    Occurs after the worksheet is recalculated, for the Worksheet object.
    Syntax

    expression.Calculate

    expression A variable that represents a Worksheet object.

    Return Value
    nothing

    Example

    This example adjusts the size of columns A through F whenever the worksheet is recalculated.
    Private Sub Worksheet_Calculate()
        Columns("A:F").AutoFit
    End Sub
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  5. #5
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Thanks - now I understand.

    However, I am now getting Run-time Error 424 - Object Required, yet I have not used any variables in my code and it works with no errors when under Worksheet_Change

  6. #6
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    What code are you using?
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  7. #7
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    The code I am using is as follows:

    With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("A5:A10", "E5:E10", "I5:I10"), .Cells) Is Nothing Then
    Application.EnableEvents = False
    With .Offset(0, 1)
    .NumberFormat = "dd mmm yyyy"
    .Value = Date
    End With
    Application.EnableEvents = True
    End If
    End With
    Regards,
    Greg

  8. #8
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Would this work for you?

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        Dim rngtest As Range
        If Target.Count > 1 Then Exit Sub
        Set rngtest = Range("A5:I10")
        If Not Application.Intersect(Target, rngtest) Is Nothing Then
            With Target
                If .Count > 1 Then Exit Sub
                Application.EnableEvents = False
                With .Offset(0, 1)
                    .NumberFormat = "dd mmm yyyy"
                    .Value = Date
                End With
                Application.EnableEvents = True
            End With
        End If
    End Sub
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  9. #9
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Thanks Jeff,

    Your code works nicely to solve the run-time error, but the original problem remains - the timestamp will only update in response to a manual entry. Nothing happens if the entry is produced as a result of a formula.

    I have attached a test spreadsheet so you can take a look yourself.

    This appears to be one of those deceptively difficult problems to solve.

    Greg

    Timestamp_test_spreadsheet.xlsm

  10. #10
    Valued Forum Contributor p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003-2010
    Posts
    377

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Here is a macro that should work as you want.
    It actually looks at the target and makes sure it is within the whole table. I think it should only looks at column A and B but this is something you could change yourself. If value of the row of the target cell and column C is 1 then the cell of that row and column D will be set to actual date.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngtest As Range
    If Target.Count > 1 Then Exit Sub
    Set rngtest = Range("A2:C11")
    If Not Application.Intersect(Target, rngtest) Is Nothing Then
      Application.EnableEvents = False
      If Cells(Target.Row, "C") = 1 Then
        With Cells(Target.Row, "D")
          .NumberFormat = "dd mmm yyyy"
          .Value = Date
        End With
      End If
    End If
    Application.EnableEvents = True
    End Sub
    Last edited by p24leclerc; 01-26-2012 at 09:44 PM.

  11. #11
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,573

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Sorry about that Greg I though for sure I had the Worksheet_Calcualte event.

    I'm not all that sure at how to solve this one. Let me ask the experts how they would approach this.
    HTH
    Regards, Jeff

    If you like the answer(s) provided, why not add some reputation by clicking the * below
    Please use [ Code ] tags when posting [ /Code ]
    Please view/read the Forum rules --- How to mark a thread as solved

  12. #12
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    You'll need to store the current values of the cells off somewhere they can be "checked" against the current values in the watched range(s). So, I'm going to assume we can use column AA to watch A, AE to watch E, and AI to watch I, 26 columns to the right.

    Option Explicit
    
    Private Sub Worksheet_Calculate()
    Dim CELL As Range
    
    Application.EnableEvents = False
        For Each CELL In Range("A5:A10, E5:E10, I5:I10")
            If CELL.Value <> CELL.Offset(, 26).Value Then
                With CELL.Offset(, 1)
                  .NumberFormat = "dd mmm yyyy"
                  .Value = Date
                End With
                CELL.Offset(, 26).Value = CELL.Value
            End If
        Next CELL
    Application.EnableEvents = True
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  13. #13
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Awesome - you are a legend! Many thanks!

  14. #14
    Registered User
    Join Date
    01-24-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    Not quite solved.

    JBeaucaire's code does a great job of watching the code and placing the timestamps. However, every time you open excel the cells which have previously been timestamped update to today's date. Clearly this is not what was intended!

    Any ideas how to solve this little problem?

    The latest code (as used in the attached spreadsheet) is as follows:

    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim CELL As Range
    
    Application.EnableEvents = False
        For Each CELL In Range("C2:C11")
            If CELL.Value <> CELL.Offset(, 2).Value Then
                With CELL.Offset(, 1)
                  .NumberFormat = "dd mmm yyyy"
                  .Value = Date
                End With
                CELL.Offset(, 2).Value = CELL.Value
            End If
        Next CELL
    Application.EnableEvents = True
    End Sub
    Attached Files Attached Files

  15. #15
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Timestamp not calculating when referencing a calculated (IF) cell

    The code as shown does not change any value in column D unless the values in column C and column E no longer match. I see no reason to think they would change. I manually set the column D values back to a few days ago, then saved and closed/opened the file multiple times and the dates did not change.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0