I have a list of numbers running sequentially 1-X in a column. These numbers restart at random intervals (i.e. 1,2,3,4,1,2,3,4,5,6,1,2,3,1,2...) but sometimes have a repetition (i.e. 1,2,3,4,4,5,1,2,3,1,2,3,4,5,1,2,2,3....) etc.
I want to be able to count just the repetitions. In the last example, the value I would want returned would be 2 (the 4 & 2 repeated). How can I do this?
Thank you!
Last edited by Atkinson501; 08-17-2011 at 05:29 PM.
Welcome to the forum.
Suppose the data from your second example is in F1:F18.
This formula gives the result 2:
F1:F17 deliberately omits the last cell (F18).=SUMPRODUCT(--(F1:F17=F2:F18))
F2:F18 deliberately omits the first cell (F1).
Brilliant. Thank you!
For curiosity: what do the operators -- do in the expression?
Looking at the Function Arguments screen for SUMPRODUCT, I understand why I would have to use D1:D(Last cell-1)=D2:D(Last cell), to have the identically sized arrays for the function to work, but I guess I'm missing the overall picture here.
I love having the solution to my immediate problem, but I want to understand how to get there on my own as well.
Hi,
Good question....For curiosity: what do the operators -- do in the expression?
In Excel, when you use the equality operator (=) to compare two operands, the result is a boolean: True or False. For example, A1=A1 returns True. SUMPRODUCT() ignores boolean values because is designed to work with numbers, so we have to find a way to convert the boolean results (Trues and Falses) into numeric equivalents (1s and 0s). A trick to do this is to perform an arithmetic operation on the boolean result - any arithmetic operator will do:
By performing arithmetic, Excel implictly understands that we're working with numbers and will return numeric results.(A1=A1)+0 returns 1 (A1=A1)*1 returns 1 --(A1=A1) returns 1 (A1=A1)-0 returns 1 etc....
So which arithmetic operator do you use? Often you'll see people using two unary minuses because:
(1) the unary minus is high up in the operator precedence list
(2) it's fractionally faster to calculate than the alternatives
For more info, see here -
http://www.xtremevbtalk.com/showpost...33&postcount=5
Fascinating explanation. Learn something new everyday. Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks