+ Reply to Thread
Results 1 to 2 of 2

Worksheet calculate - run macro on cell increase not decrease

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Question Worksheet calculate - run macro on cell increase not decrease

    Morning,

    Just a quick question - I currently have macros running on a Worksheet Calculate function. Can I change the VBA so that it only runs the macro if the cell value goes up rather than if the cell value changes?

    Thanks

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Worksheet calculate - run macro on cell increase not decrease

    Try entering the following in the appropriate worksheet module:
    Dim tgtPrev As Variant
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    tgtPrev = Target.Value
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Value > tgtPrev Then
        ' Target value has increased - enter your code here
    End If
    tgtPrev = Target.Value
    End Sub
    Be aware it will only work correctly for changes to single cells though, so selecting multiple cells and deleting / pasting / changing values will not work as intended.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] I need Increase/Decrease/Equal/NA fields to calculate in formula... HELP
    By CNNNN in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-04-2012, 12:43 PM
  2. Spinbutton userform increase/decrease current cell on worksheet
    By Stingone in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-21-2012, 03:56 PM
  3. Replies: 3
    Last Post: 09-18-2012, 01:01 AM
  4. Formula to calculate Increase/Decrease
    By howard101 in forum Excel General
    Replies: 7
    Last Post: 08-01-2012, 03:56 AM
  5. Nested IF statements to calculate increase / decrease
    By silkscreen in forum Excel General
    Replies: 2
    Last Post: 03-27-2010, 05:46 AM

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