+ Reply to Thread
Results 1 to 13 of 13

Freezing calculated values as we move forward in time

Hybrid View

  1. #1
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    Smile Freezing calculated values as we move forward in time

    I have a very simple model attached that describes how a column of numbers (Range A) is calculating the forward progress of a variable. The progression of this variable is only valid if the previous members of the variable progression remain unchanged. So, it's okay to calculate the latest member of the progression but not the values before it. I know this can be done with full VBA but I am looking for a user-defined function that might provide for a simplier solution. I have struggled for a few days on this and can't figure it out.
    Thank you in advance for any offering of your time.

    Steve Druley
    Attached Files Attached Files
    Turn Data into Information
    Turn Information into Knowledge
    Turn Knowledge into Direction
    Turn Direction into Leadership
    Turn Leadership into Results
    Stephen Druley

    It's not how quickly you think
    But how deeply you think
    The quality of thinking is measured
    by remoteness to conformance
    Stephen Druley

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Freezing calculated values as we move forward in time

    If I understood correctly. Maybe so
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("M2:M11")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    If Target.Offset(-1) <> "" Then
        With Target.Offset(4, -7)
            .Value = .Value
            .Offset(, 2).Value = .Value
        End With
    End If
    Application.EnableEvents = True
    End Sub
    Attached Files Attached Files

  3. #3
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Freezing calculated values as we move forward in time

    There is no direct way I can think of, although you could use timers to replace the cell formula with its value. A simpler, but slightly ugly, workaround would be to have the function add a comment to its cell on first calculation and then return the comment value subsequently

    Function FreezeVal(rngIn As Range)
       If rngIn.Value <> "" Then
          If Not Application.Caller.Comment Is Nothing Then
             FreezeVal = Val(Application.Caller.Comment.Text)
          Else
             FreezeVal = rngIn.Value
             Application.Caller.AddComment CStr(rngIn.Value)
          End If
       End If
    End Function
    Good luck.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Freezing calculated values as we move forward in time

    I can't see what is complicated in:

    Private Sub Worksheet_Change(ByVal Target As Range)
      If Not Intersect(Columns(13), Target) Is Nothing Then If Target.Offset(5, -5) = "" Then Target.Offset(5, -5) = Target.Offset(5, -7).Value
    End Sub



  5. #5
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    Re: Freezing calculated values as we move forward in time

    Gentlemen,

    Such power in one thread. Thanks to everyone.
    Column 13, in the example, was only meant to facilitate the mini model. The programming logic must be confined to columns 6 and 8 with the pickup for the change event in column 6. I am okay with a change event as oppose to code confined to a module. A lot of great ideas here. I think we are getting close.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Freezing calculated values as we move forward in time

    I'd prefer an event:

    Private Sub Worksheet_Change(ByVal Target As Range)
      If Not Intersect(Columns(13), Target) Is Nothing Then If Cells(Rows.Count, 8).End(xlUp).Offset(1, -2) <> "" Then Cells(Rows.Count, 8).End(xlUp).Offset(1) = Cells(Rows.Count, 8).End(xlUp).Offset(1, -2).Value
    End Sub

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Freezing calculated values as we move forward in time

    So would I (and it has already been suggested) but SDruley did say "I know this can be done with full VBA but I am looking for a user-defined function", so...

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Freezing calculated values as we move forward in time

    Perhaps the example is extremely simplified from the real situation.

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Freezing calculated values as we move forward in time

    A change event will not be triggered by a formula, so you would need the Calculate event. Since you did not comment on the UDF approach, I assume that is out.

  10. #10
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    Re: Freezing calculated values as we move forward in time

    UDF is fine if you have any ideas. I just love your user name. I guess that is where I am at this point.

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Freezing calculated values as we move forward in time

    I already posted a UDF...

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Freezing calculated values as we move forward in time

    If the new values in area 'C' are the result of a webquery you can use it's 'afterrefresh' event to trigger the code.
    It wil only be performed once when it's necessary; a UDF will be calculated too many times.

  13. #13
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    Re: Freezing calculated values as we move forward in time

    Have to close down this thread since the new challenge I have superceeds this one. New post to come

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1