Consulting

Results 1 to 9 of 9

Thread: Action when result of formula changed

  1. #1
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location

    Action when result of formula changed

    Hi.

    I am trying to run a macro when the result of a calculation changes.

    A1 on Sheet1 contains =Sheet2!A1+1

    I have tried Worksheet_Change event but it doesn't detect it.

    Any ideas?

    Thanks
    Semper in excretia sumus; solum profundum variat.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use the Calculate event.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Thanks for quick reply.

    I looked at that but don't understand it. Could you give me an example please?

    Many thanks
    Semper in excretia sumus; solum profundum variat.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like this

    [vba]

    Private Sub Worksheet_Calculate()
    Static PrevValue As Variant

    If Me.Range("L1").Value <> PrevValue Then

    MsgBox "yes"
    End If
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Feb 2011
    Posts
    75
    Location
    Hello,

    in the VBEditor, click the sheet on which change you want to react. Above the code window, select "Calculate" from the drop-down, add your code in the sub. It's that easy.

    HTH,
    Isabella

  6. #6
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Thanks xld and IBihy
    Semper in excretia sumus; solum profundum variat.

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please remember to mark your threads Solved.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Has the 'mark it solved' link moved? Can't find it, sorry
    Semper in excretia sumus; solum profundum variat.

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you're using Chrome it doesnt show, but it's in the usual place.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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