+ Reply to Thread
Results 1 to 11 of 11

Concatenate 2 ranges with a countif formula.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Concatenate 2 ranges with a countif formula.

    Good day,

    Is there a way to concatenate 2 ranges and do a countif formula?
    My problem is, I have data in column A and data in column B, both of them can be concatenated to give me a unique list in column D
    =A7&B7
    .

    II used this formula I found on Chip Pearson's site:
    =IF(MAX(COUNTIF(INDIRECT("D7:A"&(MAX((D7:D2000<>"")*ROW(D7:D2000)))),INDIRECT("A2:A"&(MAX((D7:D2000<>"")*ROW(D7:D2000))))))>1,"Duplicates","No Duplicates")
    But is there a code or a more advanced formula that can be used to eliminate the helper column D?


    Thanks,
    Xrull
    Last edited by Xrull; 08-17-2010 at 11:11 PM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,103

    Re: Concatenate 2 ranges with a countif formula.

    You can use COUNTIFS with XL 2007:

    =COUNTIFS($A$7:$A$15,A7, $B$7:$B$15,B7)
    Never use Merged Cells in Excel

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Concatenate 2 ranges with a countif formula.

    It seems you want a unique count in which case

    XL2007+

    =SUMPRODUCT(($A$7:$A$15&$B$7:$B$15<>"")/COUNTIFS($A$7:$A$15,$A$7:$A$15&"",$B$7:$B$15,$B$7:$B$15&""))

    Pre XL2007

    =SUMPRODUCT(--($A$7:$A$15&$B$7:$B$15<>""),--(MATCH($A$7:$A$15&"@"&$B$7:$B$15,$A$7:$A$15&"@"&$B$7:$B$15,0)=(ROW($A$7:$A$15)-ROW($A$7)+1)))

    edit:

    If you're trying to ascertain as to whether or not duplicates exist you can test the output of the above to the count of non-blank/non-null entries*
    (method for doing this will depend on whether range contains Nulls and whether or not if A is not blank B might be and vice versa)
    Last edited by DonkeyOte; 08-16-2010 at 02:33 AM.

  4. #4
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Concatenate 2 ranges with a countif formula.

    DonkeyOte,

    I tried your formula, but I need it to prevent a duplicate based on the two adjacent cells.
    Column A has the persons name, and column C has a ticket number. If the person's name is in cell A1, and ticket number is in C1, and the person's name is in A500, and he/she uses the same number in C500 the formula would indicate that the employee had used that ticket number earlier.

    I inserted another column so the formula now looks like this:
    =SUMPRODUCT(--($A$7:$A$15&$C$7:$C$15<>""),--(MATCH($A$7:$A$15&"@"&$C$7:$C$15,$A$7:$A$15&"@"&$C$7:$C$15,0)=(ROW($A$7:$A$15)-ROW($A$7)+1)))
    Thanks,
    Xrull

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Concatenate 2 ranges with a countif formula.

    I'm not sure if the above is a question or not ?

    It would seem you have adapted the formula to use Column C rather than B - other than that they would appear to be identical, no ?

    If your intention / requirement is to run a duplicate flag on each row I would suggest alternatives.

    If needed post a sample file and outline desired results.

  6. #6
    Forum Contributor
    Join Date
    07-29-2008
    Location
    New York
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    145

    Re: Concatenate 2 ranges with a countif formula.

    DonkeyOte,
    I've uploaded a file with an example.
    Thanks,
    Xrull

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Concatenate 2 ranges with a countif formula.

    Quote Originally Posted by DonkeyOte post#3
    If you're trying to ascertain as to whether or not duplicates exist you can test the output of the above to the count of non-blank/non-null entries*
    (method for doing this will depend on whether range contains Nulls and whether or not if A is not blank B might be and vice versa)
    Does the above not cover this ?

    ie compare unique count to count of non-blanks - if not the same you have duplicates.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Concatenate 2 ranges with a countif formula.

    Another alternative to the above would be to use a Frequency Array

    =COUNT(IF(FREQUENCY(IF(A7:A9&C7:C9<>"",MATCH(A7:A9&"@"&C7:C9,A7:A9&"@"&C7:C9,0)),ROW(A7:A9)-ROW(A7)+1)>1,1))
    confirmed with CTRL + SHIFT + ENTER

    (if greater than 0 then duplicates)
    Last edited by DonkeyOte; 08-17-2010 at 07:46 AM. Reason: typo in formula re: @

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Concatenate 2 ranges with a countif formula.

    A unique list in column D based on the values in columns A and C

    Sub unique()
      [D1:D18] = [if(countif(offset(D1,,,row(A1:A18)-if(row(D1:D18)=1,0,1)),A1:A18 & C1:C18)=0,A1:A18 & C1:C18,"")]
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1