Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

run macro if a value in cell is not changed

Posted on 2009-12-28
11
Medium Priority
?
234 Views
Last Modified: 2013-11-25
Hi,
Is there a way to check if a value in a cell is not changed?.  For instance, if the value in  cell A1 is not changed then i want to do some action.  Here is the pseudocode for what i want:

if Sheet9 Cell A1 is not changed
then run macro1
else run macro2
exit sub

thanks
0
Comment
Question by:karinos57
  • 6
  • 5
11 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 26132322
When do you want to do this check? When the workbook is saved? When another cell is changed?

Kevin
0
 

Author Comment

by:karinos57
ID: 26132392
there is a button that the user clicks, the macro is triggered when the user clicks it; this macro does some other staff, so i want to do the checking while this macro is running
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 26132419
Easy enough. You will need to have a second cell in which to store the last known value (set when the button is clicked but after you do the comparison).

Kevin
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 26132439
Assume you are using B1 as the copy of A1 and A1 is the cell being tested:

If A1 = B1 Then
   Macro1
Else
   Macro2
End If
B1 = A1

Kevin
0
 

Author Comment

by:karinos57
ID: 26132503
Okay, the code below checks if the value in A5 is changed then it sets
Application.Cursor = xlWait
and so on....
But what i want is - Can i change this code into like this: check if the value in A5 is not changed then set
Application.Cursor = xlWait
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Not Application.Intersect(Target, Me.Range("A5")) Is Nothing Then
        ' At least one cell of Target is within the range A1:C10.
        Application.Cursor = xlWait
        Application.StatusBar = "Please be patient - extracting data over the Network"

    Else
        ' No cell of Target in in the range A1:C10. Get Out.
    Exit Sub
End If
End Sub

Open in new window

0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 26132520
Using X99 (random) as the copy:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Not Application.Intersect(Target, Me.Range("A5")) Is Nothing Then
        ' At least one cell of Target is within the range A1:C10.
        If A5 = X99 Then
            Application.Cursor = xlWait
            Application.StatusBar = "Please be patient - extracting data over the Network"
        End If
        X99 = A5
    Else
        ' No cell of Target in in the range A1:C10. Get Out.
    Exit Sub
End If
End Sub

Kevin
0
 

Author Comment

by:karinos57
ID: 26132579
one more thing Kevin, if the value is changed; can i change the mouse cursor back to its original like this
Application.Cursor = xlDefault

Open in new window

0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 26132586
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Not Application.Intersect(Target, Me.Range("A5")) Is Nothing Then
        ' At least one cell of Target is within the range A1:C10.
        If A5 = X99 Then
            Application.Cursor = xlWait
            Application.StatusBar = "Please be patient - extracting data over the Network"
        Else
            Application.Cursor = xlDefault
        End If
        X99 = A5
    Else
        ' No cell of Target in in the range A1:C10. Get Out.
    Exit Sub
End If
End Sub

Kevin
0
 

Author Comment

by:karinos57
ID: 26132903
Kevin,
this is not working.  the cursor has not changed back to its original.  The whole thing is not working properly like if i just click cel A5 - it seems the code re-runs itself.  Is there a different way or more effiecient way to do this?  thanks
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 750 total points
ID: 26132926
I'm confused. What are you trying to do? What I provided is a response to this request and only this request:

"Is there a way to check if a value in a cell is not changed?.  For instance, if the value in  cell A1 is not changed then i want to do some action."

I also provided a specific solution for this psuedo code:

if Sheet9 Cell A1 is not changed
then run macro1
else run macro2
exit sub

Please be very specific.

Kevin
0
 

Author Closing Comment

by:karinos57
ID: 31670451
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question