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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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.


BIDSIZE(B)BID(C)ASK(D)ASKSIZE(E)CumulativeVOLUME(F)LASTPrice(G)(H)LASTVOL(I)Price*QTY(J)Σ(Price*QTY)(K)ΣVOL(L)VarX(M)
50040046.7446.752510046.74200=I3 * G3uses a macrouses a macro=K3/L3

<tbody>
</tbody>


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,215,761
Messages
6,126,735
Members
449,333
Latest member
Adiadidas

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