Excel/Counting

Advertisement


Question
Hi Bob, thanks for viewing my question. I have a worksheet that connects to a datafeed, after some minor number crunching one cell (A1), fluctuates to either 1 or 0 several hundred times/day. Is there a way I can capture/record the number of times it reads 1?  Would I need some sort of persistent variable or bin that can store each "1" reading?

Thanks Al

Answer
Maybe something like this would work:
right-click the sheet tab, select View Code, put this in.
Cell A2 is keeping track of the # of times A1 is a 1 whenever the number crunching is done.

Public ct As Long
Private Sub Worksheet_Calculate()
   Worksheet_Change Range("A1")
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
   If Range("A1").Value = 1 Then ct = ct + 1
   Application.EnableEvents = False
   Range("A2").Value = ct
   Application.EnableEvents = True
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bob Umlas

Expertise

I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/

Experience

Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Publications
Excellence, The Expert, Microsoft

Education/Credentials
BA in math, Hofstra University, 1965

Awards and Honors
MVP
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2016 About.com. All rights reserved.