Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

dynamic data counter

0

Hi Good morning Sir..would just like to ask your assistance on how I'll be able to count the events from a single cell?

basically, i have a single cell that changes from "0" to "1" vice versa. (a data from PLC that is connected to excel thru (DDE ) dynamic data exchange. and I want to record how many times it changes from 0 to 1 ...thank you

Answer
Discuss

Discussion

Monexcel. Please respond to Willie's Answer, preferably marking his Answer as Selected (if it works). 
John_Ru (rep: 6142) Feb 9, '23 at 6:36 pm
Add to Discussion

Answers

0

Hello monexcel and welcome to the forum.

This can be easily achieved using a worksheet event as below:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$2" Then
    Range("D2").Value = Range("D2").Value + 1
End If

End Sub

Place this code in the worksheet code module.

Edit $B$2 and D2 to suit. As is, the value in D2 will increase until it is reset to zero.

This can be done by adding a button to the sheet with a simple macro.

If this is your prefered answer just remember to mark it as selected.

Cheers   :-)

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login