+ Reply to Thread
Results 1 to 5 of 5

Thread: Count direct duplicates only

  1. #1
    Registered User
    Join Date
    08-17-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    2

    Count direct duplicates only

    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.

  2. #2
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Count direct duplicates only

    Welcome to the forum.

    Suppose the data from your second example is in F1:F18.
    This formula gives the result 2:
    =SUMPRODUCT(--(F1:F17=F2:F18))
    F1:F17 deliberately omits the last cell (F18).
    F2:F18 deliberately omits the first cell (F1).
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  3. #3
    Registered User
    Join Date
    08-17-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Count direct duplicates only

    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.

  4. #4
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Count direct duplicates only

    Hi,
    For curiosity: what do the operators -- do in the expression?
    Good question....

    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:
    (A1=A1)+0      returns 1
    (A1=A1)*1      returns 1
    --(A1=A1)      returns 1
    (A1=A1)-0      returns 1
    etc....
    By performing arithmetic, Excel implictly understands that we're working with numbers and will return numeric results.


    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
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  5. #5
    Registered User
    Join Date
    07-27-2011
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Count direct duplicates only

    Fascinating explanation. Learn something new everyday. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0