Macro wont run when a Cell changes due to incoming Real-Time Data! How to bypass need for manual intervention??

DrLight

New Member
Joined
Jun 3, 2014
Messages
11
I want to run the bellow macro whenever cell F3 increases. I need this to happen without manual intervention because F3 is increasing due to incoming RTD server data. As it stands, unless I manually update something in my sheet the macro does not run.
Code:
Public Prev_Val As Long


Private Sub Worksheet_Change(ByVal Target As Range)
'using a Public variable to store the previous value
    If Range("F3") <> Prev_Val Then
        Application.EnableEvents = False
        Range("I3") = Range("F3") - Prev_Val
        Prev_Val = Range("F3")
        Application.EnableEvents = True
    End If
End Sub


I've tried using:

Code:
If Target.Address = "$F$3" Then
'my code

But that does not seem to work either.
Context: I'm using RTD with a stock simulator to automatically populate fields in Excel. Several calculations are done on the incoming data, but I cant do any of them without having Cell I3 work properly!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If, whenever new data comes in, the worksheet is recalculated, try changing the code to a Workbook_SheetCalculate event
 
Upvote 0
If you want to retain the data after the procedure runs I always use the Static rather than the public command ... like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'using a Public variable to store the previous value

Static Prev_Val As Long
    If Range("F3") <> Prev_Val Then
        Application.EnableEvents = False
        Range("I3") = Range("F3") - Prev_Val
        Prev_Val = Range("F3")
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
->I tried your solution, Shadow, but it still only updates I3 when I change something in the sheet manually (which is strange because F3 is changing almost every 2 seconds automatically).

-> Michael could you put that option in context with my code so I can copy past (I'm still [very] novice - trying to avoid errors)

Best,
D
 
Upvote 0
Just reread your post and realised there is no "calculations"
Is that all the code ??
Does the imported data trigger any recalcs in the sheet ?
 
Upvote 0
No there's more. The sheet looks like this. Note: Bidsize through Last Price are populated via RTD. The rest are for my formulas.

The cell under Cumulative VOLUME is F3. Cell under Last Vol is I3.


[TABLE="class: cms_table_grid, width: 1144"]
<tbody>[TR]
[TD]BIDSIZE(B)[/TD]
[TD]BID(C)[/TD]
[TD]ASK(D)[/TD]
[TD]ASKSIZE(E)[/TD]
[TD]CumulativeVOLUME(F)[/TD]
[TD]LASTPrice(G)[/TD]
[TD](H)[/TD]
[TD]LASTVOL(I)[/TD]
[TD]Price*QTY(J)[/TD]
[TD]Σ(Price*QTY)(K)[/TD]
[TD]ΣVOL(L)[/TD]
[TD]VarX(M)[/TD]
[/TR]
[TR]
[TD]500[/TD]
[TD="align: right"]400[/TD]
[TD="align: right"]46.74[/TD]
[TD="align: right"]46.75[/TD]
[TD="align: right"]25100[/TD]
[TD="align: right"]46.74[/TD]
[TD="align: right"][/TD]
[TD]200[/TD]
[TD]=I3 * G3[/TD]
[TD="align: right"]uses a macro[/TD]
[TD="align: right"]uses a macro[/TD]
[TD]=K3/L3[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


The formula in F3 looks like this: =RTD("qj.position.excel", , "FEED", $A3,F$1).

Once I can figure out I3 I have to code macros for K3 and L3, which are running cumulative sums of J3 and I3, respectively.

I planned on using something like the following (although these have not been functioning consistently -not sure whats wrong).

Code:
[COLOR=#333333][FONT=Verdana]Private Sub Worksheet_Change(ByVal Target As Excel.Range)
 With Target 
   If .Address(False, False) = "K3" Then 
      If IsNumeric(.Value) Then 
      Application.EnableEvents = False
      Range("K3").Value = Range("K3).Value + Range("J3").Value 
      Application.EnableEvents = True 
      End If 
   End If
End With
End Sub
[/FONT][/COLOR]


Your help (or anyone else's reading) is uber welcome.

-DLight.
 
Last edited:
Upvote 0
Problem solved:

Code:
Public Prev_Val As Long


Private Sub Worksheet_Calculate()
Dim rngF3 As Range
Set rngF3 = Range("F3")
      If rngF3 <> Prev_Val Then
         Application.EnableEvents = False
         Range("I3") = rngF3 - Prev_Val
         Prev_Val = rngF3
         Application.EnableEvents = True
           
        If IsNumeric(Range("J3").Value) Then
            Application.EnableEvents = False
            Range("K3").Value = Range("K3").Value + Range("J3").Value
            Application.EnableEvents = True
        End If


        If IsNumeric(Range("I3").Value) Then
            Application.EnableEvents = False
            Range("L3").Value = Range("L3").Value + Range("I3").Value
            Application.EnableEvents = True
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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