
Please help identify active row in DDE update of Excel spreadsheet Gary G
I need help with certain aspects of VBA code. I receive data in Excel via Dynamic Data Exchange
from another program.
Data updates are unpredictable -- they may occur at any given moment and randomly affect any one
of several hundred rows in the Excel spreadsheet.
Whenever a given row is updated, I need to call VBA and compute some of my own statistics which
will be displayed in other columns of that same row.
I use the following routine to respond to arriving data:
Sub TrapData()
Worksheets("Sheet1").OnData = "Compute"
End Sub
I have a fair amount of code in the Compute routine which uses .Offset to read and write data in
other columns of the active row. My dilemma is how to accurately detect the actual row where
new data have just arrived. What I am currently doing only detects the "active" row in which a
cell is visually highlighted on the screen, not where the data are actually coming in. I am
using the following instructions:
Sub Compute()
Dim Rval As String
For Each myRow In Selection
Rval = myRow.Address
If Left(Rval, 2) = "$B" Then 'tests for data arriving in Col. "B"
Set L = mrRow.Offset(0, 0)
Set O = myRow.Offset(0, 1)
Set C = myRow.Offset(0, 2)
C.Value = L.Value - O.Value
etc.
etc.
End If
End Sub
I know how to write the statistical code, but I am not sufficiently familiar with Objects,
Properties, and other mysteries of VBA. I'm sure this is simple for you experts in VBA. I hope
you will be kind enough to lend a helping hand.
Gary G.