#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Count?

I would like to know if I there is a way to count the number of times a value
in a cell changes. I have a spreadsheet that reads in data from a "PLC" and
the data changes throughout the day, what I am looking for is a way to count
the times that "value" in the cell changed. Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Count?

Here is one option.

For the example, I'm looking for how many times the value in cell C5
changes. The count appears in cell G2 and I've used cell G1 to store the
last changed value from C5 so there is a reference for comparison, if and
when the value of C5 is changed. The code goes in the worksheet, not a
module.

'_________________________________________________ _

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

If Not Intersect(Target, Me.Range("C5")) Is Nothing Then
If Not Target.Value = Me.Range("G1").Value Then
Me.Range("G2").Value = Me.Range("G2").Value + 1
Me.Range("G1").Value = Target.Value
End If
End If

Application.EnableEvents = True

End Sub

__________________________________________________

Steve
"Mark J" wrote in message
...
I would like to know if I there is a way to count the number of times a
value
in a cell changes. I have a spreadsheet that reads in data from a "PLC"
and
the data changes throughout the day, what I am looking for is a way to
count
the times that "value" in the cell changed. Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Count?

As a worksheet -change event this will count how many times cell A2 was
updated and put the count in B2. This is different from your statement
"count the number of times a value in a cell changes." In other words, it
does not compare the new value to the old value or any previous value. If
cell A2 was updated 4 times, but each time the value remained the same, it
will give you the count of 4, even though the number value of A2 never
changed. Is that what you want?

Option Explicit
Public counter As Long

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
counter = counter + 1
Target(1, 2).Value = counter
Exit Sub
End If
End Sub

Put this code in the Worksheet code module.
Mike F
"Mark J" wrote in message
...
I would like to know if I there is a way to count the number of times a
value
in a cell changes. I have a spreadsheet that reads in data from a "PLC"
and
the data changes throughout the day, what I am looking for is a way to
count
the times that "value" in the cell changed. Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Employee Work Time - Don't Double-count Overlapping Apts. J Excel Worksheet Functions 0 April 27th 07 05:52 AM
Excel 2000, count, sort a list & count totals? sunslight Excel Worksheet Functions 1 April 9th 07 05:46 PM
Excel Count characters in a textbox to display character count? [email protected] Excel Programming 1 February 8th 07 06:31 AM
Count Intervals of 2 Numeric values in same Row and Return Count across Row Sam via OfficeKB.com Excel Worksheet Functions 12 September 24th 05 10:58 PM
Count Intervals of Filtered TEXT values in Column and Return Count across a Row Sam via OfficeKB.com Excel Worksheet Functions 9 July 31st 05 03:37 AM


All times are GMT +1. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"