I need to record the number of transitions from a down state (0) to up state (1) in a single column in excel and I am wondering whether there is some kind of logic like this available in Excel or whether I can program this kind of logic in VBA. I am not very well versed in VBA however, so if any links are available, that would be great.

  • Can you give us an example of your data? – CLockeWork Dec 2 '14 at 16:45

You can get the count with a single SUMPRODUCT formula. If your data is in A1:A25, you could use the following:


This counts only instances where one value in the column is 0 (and not blank) and the following value is 1.

  • beat me to it and simpler solution too. – gtwebb Dec 2 '14 at 17:23

My solution is assuming clean data starting in cell A2 and going down column A. For my formula it also assumes no data past row 1000 (adjust this upward for most real world data.

Formula is an array formula so enter using ctrl+shift+enter


How the formula works.

For each cell A2 to A1000 look for a zero, if there is a zero look in the next cell down. If there is a one in the next cell down add one to the count. Note a blank cell will count as a zero.

The end of the ranges (A1000 and A1001) just have to be past the end of the data.

enter image description here

  • 1
    I find this solution easier to grok than the currently-highest-voted answer. It's logical instead of tacking advantage of a mathematical coincidence. – corsiKa Dec 2 '14 at 22:46

If you only want to keep track of the changes from down to up (assuming your data is in column A) then all you need is =N(A2>A1) then drag the formula down.

This evaluate to TRUE if the value has increased (gone from down to up), then N(boolean) converts to this to 1 or 0.

To keep track of all state changes you'd use =N(A2<>A1)

To count all state changes you'd then sum the column.


You can use formula to detect transitions from 1 to 0 and from 0 to 1. Just be careful around blank cells!

Consider following example (see screenshot below):

column B contains binary data pattern.

C2 will contain following formula:


D2 will contain:


You will just need to autofill formula for as many rows as you need in columns C and D.

  • Amount of 1 (ones) in columnt C will represent amount of transitions from 1 to 0.
  • Amount of 1 (ones) in columnt D will represent amount of transitions from 0 to 1.

And in the end you need is to sum ones (1) in columnds C and D

In example below:


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.