Calculate Event - Run macro only once

nt82

Board Regular
Joined
Jan 29, 2009
Messages
133
hello,

I have some issue with below code...what it does is when b1>A1 then it continously runs macro BUYBEAN..what I want is to run only one time..till there is change in value in A1 and B1



Code:
Private Sub Worksheet_Calculate()
On Error GoTo ws_exit
    Application.EnableEvents = False
If Range("b1") > Range("A1") Then
 Call BUYBEAN
Else
Call SELLBEAN
End If
ws_exit:
    Application.EnableEvents = True
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Are A1 and B1 calculated cells (i.e. they have a formula)? If so, the easiest way would be to eliminate this macro and create a worksheet_change macro that monitors changes for the manual-entry cells that feed into A1 and B1.
 
Upvote 0
Actually they are values updated dynamically through a DDE link ..from an external application...

I would have used worksheet_change but it doesnt recognize any value if its DDE related...
 
Upvote 0
Hi,

Try putting it inside Worksheet_Change:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:B1")) Is Nothing Then
        On Error GoTo ws_exit
        Application.EnableEvents = False
        If Range("b1") > Range("A1") Then
            Call BUYBEAN
        Else
            Call SELLBEAN
        End If
ws_exit:
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
somehow change event is not recognizing my value in A1 and B1 so this doesnt shoot any macro..
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top