Counter when Cell Changes by Feed

Jer-XL-emy

Board Regular
Joined
Aug 27, 2007
Messages
60
Hello, back to the genius board...and back for me asking directions (I hate asking for directions when I am lost - like most men, but here I get some social intellectual value when I find myself lost :)

Here is my problem - I am trying to get a counter to count +1 every time a cell changes (easy enough since I have recieved many that help me out with that), but the brain buster is that I need it to count everytime a cell changes by a DDE feed (the previous only worked manually). So for that I am told it must be a _calculate event (vs a _change event).

Now Boller (long time poster and I beleive genius) made me a little (well actually big) thinger that worked. It reads


Code:
Private Sub Worksheet_Calculate() 
Dim rng As Range, cell As Range
Application.EnableEvents = False
[Z:AA].ClearContents
Range([Z1], [V65536].End(xlUp)(1, 6)).FormulaR1C1 = "=IF(RC[-4]=RC[-2],"""",1)"
On Error Resume Next
Set rng = [Z:AA].SpecialCells(xlCellTypeFormulas, 1)
On Error GoTo 0
If Not rng Is Nothing Then
    For Each cell In rng
        cell(1, -8) = cell(1, -8) + 1
    Next
End If
[X:Y] = [V:W].Value
Range([Z1], [V65536].End(xlUp)(1, 6)).FormulaR1C1 = "=IF(RC[-4]=RC[-2],"""",1)"
Application.EnableEvents = True 
End Sub


Thats after a little set up Macro.

The problem is that it has a latency issue as it calculates down the column and then Xl freezes (has a hourglass) for about 4 seconds on a single calculation and I can here my processor fan crank (I have a newer machine and 2007 excel - that is suppose to use my dualcore quite efficently - so I am told). In the real world of the application, there could be multiple calcs (like 25) going on at the same time - thus the problem.

So I call on you all to maybe see what is needed (if its possible) to fix the latency stall of my worksheet as there are other independent cells that are in calculation mode as well (though when testing 'er I used one calculation)?

What is the problem likely caused by - the error work around or the large column as a range or...?

I have no problem with have another worksheet or wbook calculate this and have it linked (or =(reference cell)) to the wsheet I want visible as too leave the other independant cells alone doing their job - if necessary

Nor do I have a problem using a tighter range - for reference it is
counter cells Q 6-242 and R 6-242 cells that need counting (DDE feed) V 6-242 and W 6-242

For those who are studius the previous post is http://www.mrexcel.com/board2/viewtopic.php?p=1396040#1396040

So this has been a weeklong adventure and while it hasbeen fun, fun has changed to frustration - lol,

I call to you all to fix me up, until the next next week I get stuck (big project probably never ending now that I realize the power of coding in Excel - - and I apprciate your guys' help
Thanks in advance

Jeremy
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
<table border="1" bgcolor="White"><caption ALIGN=left><font size="2" face=Courier New>Example VBA Code:</FONT></caption><tr><td><font size="2" face=Courier New>  The following method is often enough...
  
  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> Worksheet_Calculate()
       <font color="#0000A0">Dim</font> rng <font color="#0000A0">As</font> Range, cell <font color="#0000A0">As</font> Range
       Application.EnableEvents = False
      
      <font color="#008000"> 'perform a full calculation on this worksheet without</font>
      <font color="#008000"> 'firing redundant events</font>
       Me.Calculate
      

       [Z:AA].ClearContents
       Range([Z1], [V65536].End(xlUp)(1, 6)).FormulaR1C1 = "=IF(RC[-4]=RC[-2],"""",1)"
       <font color="#0000A0">On</font> <font color="#0000A0">Error</font> <font color="#0000A0">Resume</font> <font color="#0000A0">Next</font>
       <font color="#0000A0">Set</font> rng = [Z:AA].SpecialCells(xlCellTypeFormulas, 1)
       <font color="#0000A0">On</font> <font color="#0000A0">Error</font> <font color="#0000A0">GoTo</font> 0
       <font color="#0000A0">If</font> <font color="#0000A0">Not</font> rng <font color="#0000A0">Is</font> <font color="#0000A0">Nothing</font> <font color="#0000A0">Then</font>
           <font color="#0000A0">For</font> <font color="#0000A0">Each</font> cell <font color="#0000A0">In</font> rng
               cell(1, -8) = cell(1, -8) + 1
           <font color="#0000A0">Next</font>
       <font color="#0000A0">End</font> <font color="#0000A0">If</font>
       [X:Y] = [V:W].Value
       Range([Z1], [V65536].End(xlUp)(1, 6)).FormulaR1C1 = "=IF(RC[-4]=RC[-2],"""",1)"
       Application.EnableEvents = True
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table>

Another option that works if you are using an actual DDE link in your range is the "SetLinkOnData" method. Research this method in Excel VBA help. This method will fire whenever your link is updated.

Yet another option is to link a hidden textbox to your range. When the range is changed, capture this in the textbox's change event.
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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