Increment value of cell if another cell changes value

denisined12

New Member
Joined
Oct 9, 2019
Messages
6
Hello,
Is there a way in Macros or VBA to increment the value of a cell by 1 if another cell changes value?

Ill give the example:

In cells A1 to A56 I have links to another workbook that update every few seconds. I would like to count in Column B -- B1 to B56 -- The changes from each cell.
A1 updates its value 6 times next minute -- B1 displays 6
A2 updates its value 11 times next minute -- B2 displays 11

If anyone could help me I would very much appreciate it!
I really hope I made myself clear in explanation.

With respect,
Denis.
 

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
Hello,

You could test the following

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Display Nb of Changes
    Application.EnableEvents = False
       Target.Offset(0, 1) = Target.Offset(0, 1) + 1
    Application.EnableEvents = True
End Sub

Hope this will help
 
Upvote 0
Hello James,

Unfortunately this is not working. The values increment only if I click in A cells and than exit. If the values change by themselves no increment is done in B column.

:(

Any suggestions?
 
Upvote 0
The issue is that changes due to formulas/linked cells do NOT trigger a Worksheet_Change event procedure. Those are only triggered when a change is manually made to a cell (i.e. direct cell entry or copy/paste).
I am not sure if a Worksheet_Calculate event procedure would work instead, but you could try it and find out.
In my mind, the best place to track the number of changes would be in the Source Workbook itself. That might depend on how they get updated there.
 
Upvote 0
Thank you Joe,

Do you have any ideas how this code would look like? I have very limited knowledge on vba coding. I tried myself to change the procedure in the previous code but aint working.


Denis.
 
Upvote 0
You could test the following

Code:
Private Sub Worksheet_Calculate()
Dim OldVal As Variant, NewVal As Variant
  Application.EnableEvents = False
    NewVal = ActiveCell.Value
    Application.Undo
    OldVal = ActiveCell.Value
    If OldVal <> NewVal Then ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value + 1
  Application.EnableEvents = True
End Sub

Hope this will help
 
Upvote 0
Still not doing so.

If it helps, I put the links in the same workbook, in another sheet, sheet2, but still updating from sheet 1. The source in sheet 1 A column are mt4 spot prices and updated with command: ='MT4'|Bid!EURUSD
Could this be the problem?
 
Upvote 0
No ... it is not the poblem ...

The issue is the live feed ...

Are you using a Reuters or Bloomberg feed ...?

You might have built-in trackers/counters for price changes ...
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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