+ Reply to Thread
Results 1 to 6 of 6

Compare 2 ranges with countifs

  1. #1
    Registered User
    Join Date
    06-11-2021
    Location
    Hungary
    MS-Off Ver
    office 365
    Posts
    4

    Compare 2 ranges with countifs

    Hello,
    I almost solved the problem, but cannot figure out the last step.
    On Sheet1 A1:Z100 I have a table with numbers only
    On Sheet2 B1:H1 I have a row with numbers only
    There are empty cells in both
    I want to count the number of rows in sheet1 table that contain at least one number from the B1:H1 range on sheet2.
    For this, I will need probably to use countifs.

    I have already set this up:=COUNTIFS(Sheet2!B1:H1,Sheet1!$A$1:$Z$100). The comparision goes well, however, the result is a table with 1s and 0s indicating the hits. How can I develop this to count the number of rows where there was a hit?
    Thank you!
    Attached Files Attached Files
    Last edited by NickThomas; 06-11-2021 at 05:50 AM. Reason: attach sample sheet

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,452

    Re: Compare 2 ranges with countifs

    Without sample worksheet, just guess:

    =SUM(MMULT(TRANSPOSE(COUNTIF(Sheet2!$B$1:$H$1,Sheet1!$A$1:$Z$100)),ROW(1:100)^0))

    Confirmed by Ctrl-Shift-Enter.
    Quang PT

  3. #3
    Registered User
    Join Date
    06-11-2021
    Location
    Hungary
    MS-Off Ver
    office 365
    Posts
    4

    Re: Compare 2 ranges with countifs

    Thank you Quang,
    I attached a sample excel to my original post.
    I tried the formula you wrote, it gives me the total number of hits. I would need something that counts the number of rows where there is a positive hit.
    So if there are 25 hits but it is only distributed into 6 rows, then I would need a formula that returns 6.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,147

    Re: Compare 2 ranges with countifs

    Try

    =SUMPRODUCT(--(MMULT(TRANSPOSE(COUNTIF(Sheet2!$B$1:$H$1,Sheet1!$A$1:$Z$100)),ROW(1:100)^0)>0))

    confirm with Ctrl+Shift+Enter

  5. #5
    Registered User
    Join Date
    06-11-2021
    Location
    Hungary
    MS-Off Ver
    office 365
    Posts
    4

    Re: Compare 2 ranges with countifs

    Thanks John, almost there, this gives actually a lower number of rows back as the numbers actually occur in. This formula misses some occurrences.
    I do not know where the problem lies though. One thing I can think of is that when I set my cursor to ROW(1:100) it will highlight the rows on sheet2 instead of sheet 1.

  6. #6
    Registered User
    Join Date
    06-11-2021
    Location
    Hungary
    MS-Off Ver
    office 365
    Posts
    4

    Re: Compare 2 ranges with countifs

    After some more reading and playing around, finally found it!

    =SUM(--(MMULT(--(COUNTIF(Sheet2!B1:H1,Sheet1!$A$1:$Z$100)),TRANSPOSE(COLUMN(Sheet1!$A$1:$Z$100)^0))>=1))

    Thanks for all the hints.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] COUNTIFS with Date Ranges
    By aldenes in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-10-2020, 01:09 PM
  2. Countifs with date ranges
    By ljbrown in forum Excel General
    Replies: 2
    Last Post: 05-17-2017, 12:48 PM
  3. Replies: 3
    Last Post: 08-18-2016, 05:26 PM
  4. COUNTIFS between two ranges
    By Blackhawks in forum Excel General
    Replies: 8
    Last Post: 03-11-2015, 03:57 PM
  5. [SOLVED] Countifs and Date Ranges
    By MercyMercyMe in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-08-2013, 07:16 PM
  6. COUNTIFS with cell ranges
    By 1.zer0 in forum Excel General
    Replies: 8
    Last Post: 10-01-2010, 06:43 AM
  7. Using COUNTIFS with dynamic ranges?
    By Kagemucha in forum Excel General
    Replies: 5
    Last Post: 07-01-2007, 11:25 AM

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