+ Reply to Thread
Results 1 to 26 of 26

Count matching data Vertical verses Horizontal values.

  1. #1
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Count matching data Vertical verses Horizontal values.

    Hello Everyone!

    I need a Formula and (VBA also to work with larger data) which can count matching data Vertical verses Horizontal values.

    For example I got 4 horizontal values in A6:D6 and 22 vertical values in the columns G1:AB4. I want A6:D6 value count match greater than 2, with each value is in G1:G4, H1:H4?.till AB1:AB4 and show result in range G6:AB6.

    Note: If possible formula and VBA can work with excel 2000 also.

    Example sheet is attached.

    Thanks and regards,
    Moti
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    Unclear - formula or VBA or both or either???

    Which version of Excel do you have?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    Is this it? In G7 copied across:

    =IF(COUNTIF(G1:G4,1)>2,"Match","")

  4. #4
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    Unclear - formula or VBA or both or either???

    Which version of Excel do you have?
    Hello AliGW, I need formula & VBA both if possible? I am using version 2010 & still older version 2000 also where I have got some programs so I request please formula & VBA could work with both version will be great always if possible. Thank you.

    Good Luck

    Thanks and regards,
    Moti

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

    Re: Count matching data Vertical verses Horizontal values.

    I don't think it's that simple. Is your actual data always 1, 1, 1, 1 in the range A6:D6, or can it be any numbers? For example, 15, 80, 9, 200. I assume it can be any numbers, and you want a VBA solution.
    Please confirm.
    Quang PT

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    If you had something newer, this would probably work:

    =IF(COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))>2,"Match","")

    But I'll leave you in Bebo's capable hands.

  7. #7
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by bebo021999 View Post
    I don't think it's that simple. Is your actual data always 1, 1, 1, 1 in the range A6:D6, or can it be any numbers? For example, 15, 80, 9, 200. I assume it can be any numbers, and you want a VBA solution.
    Please confirm.
    Hello bebo021999, I guess my question was not clearly explained, here is a new sheet where I need a Formula or VBA it is ok no problem in this example range G6:AB22 but range could be adjustable if it is VBA solution.

    Thank you.

    Thanks and regards,
    Moti
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    If you had something newer, this would probably work:

    =IF(COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))>2,"Match","")

    But I'll leave you in Bebo's capable hands.
    Hello AliGW, I needed match could be counted, any ways thank you for your help. lets wait for Bebo's reply

    Good Luck

    Thanks and regards,
    Moti

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    The count is this bit:

    =COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))

  10. #10
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    The count is this bit:

    =COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))
    Hello AliGW, unfortunately formula does not give the result as per #post7 it must count match greater than 2 only and with different values as shown.

    Please can you check?

    Good Luck

    Thanks and regards,
    Moti

  11. #11
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,008

    Re: Count matching data Vertical verses Horizontal values.

    Try this,

    G6
    Please Login or Register  to view this content.
    Committed with Ctrl+Shift+Enter. Copied down and across.
    Attached Files Attached Files

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by Motilulla View Post
    Hello AliGW, unfortunately formula does not give the result as per #post7 it must count match greater than 2 only and with different values as shown.
    That's not what you asked for!

    =IF(COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))>2,COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,)),"")

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

    Re: Count matching data Vertical verses Horizontal values.

    If you want to compare one-by-one: A6 vs G1, B6 vs G2, C6 vs G3, D6 vs G4 then count the match

    In G6:
    Please Login or Register  to view this content.
    Confirmed with Ctrl-Shift-Enter
    Drag down and accross
    In case "match" returns, try:
    Please Login or Register  to view this content.
    This is a formula-based solution. I'm not sure if it will impact the processing speed of your computer with large data. If it runs too slow, please let me know, and I can provide you with VBA code as an alternative.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by windknife View Post
    Try this,

    G6
    Please Login or Register  to view this content.
    Committed with Ctrl+Shift+Enter. Copied down and across.
    Hello windknife, yes your formula worked spot on! For both 2010 and 2000 Version perfect.

    I appreciate your help and time you took for solving by formula.

    Is it possible to get VBA?

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  15. #15
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    That's not what you asked for!

    =IF(COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,))>2,COUNT(IF(MATCH(G1:G4,TRANSPOSE($A$6:$D$6),0)=1,)),"")
    Hello AliGW, unfortunately this also does not give the require result.

    I appreciate your help.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    It does in the file you posted first!

    Good luck!

  17. #17
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Count matching data Vertical verses Horizontal values.

    Formula. ARRAY formula In G6 copied to full range
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    VBA code:
    Please Login or Register  to view this content.
    To enter ARRAY formula
    Copy and paste the formula in cell
    Press F2
    Press Ctrl+Shift+Enter together
    Excel covers the formula with {}.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  18. #18
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by bebo021999 View Post
    If you want to compare one-by-one: A6 vs G1, B6 vs G2, C6 vs G3, D6 vs G4 then count the match

    In G6:
    Please Login or Register  to view this content.
    Confirmed with Ctrl-Shift-Enter
    Drag down and accross
    In case "match" returns, try:
    Please Login or Register  to view this content.
    This is a formula-based solution. I'm not sure if it will impact the processing speed of your computer with large data. If it runs too slow, please let me know, and I can provide you with VBA code as an alternative.
    Hello bebo021999, yes both formulas worked with both 2010 and 2000 versions Spot On!
    I like the Match formula also.

    I appreciate your help and time you took for solving by formula.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  19. #19
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    It does in the file you posted first!

    Good luck!
    Hello AliGW, yes if I compare with first post your formula does give the result as request that is perfect! But later I realize my error and corrected that in #post7, I think you did not see that that has create the confusion I am sorry I agree your formula is working fine with opening post.

    I appreciate your help.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

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

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by Motilulla View Post
    Hello bebo021999, yes both formulas worked with both 2010 and 2000 versions Spot On!
    Moti
    Nice to hear it works.
    And here is VBA solution. Click the button "RUN" to run the code.
    PHP Code: 
    Option Explicit
    Sub matching
    ()
    Dim i&, j&, k&, t&, VTableHTablerngres()
    VTable Range("A6").CurrentRegion.Value ' This is left table (Vertical)
    HTable = Range("G1").CurrentRegion.Value ' 
    This is top table (Horrizontal)
    ReDim res(1 To UBound(VTable), 1 To UBound(HTable2)) ' result array

    '
    Loop thru each single cell in result array, then
    For 1 To UBound(res)
        For 
    1 To UBound(res2)
            
    0
            
            
    'compare each cell in VTable vs HTable, then count the "matching" (k)
            For t = 1 To UBound(VTable, 2)
                If VTable(i, t) = HTable(t, j) Then k = k + 1
            Next
            If k > 2 Then res(i, j) = k ' 
    save the "count" into result range
        Next
    Next
    Range
    ("G6").Resize(UBound(res), UBound(res2)).Value res ' paste the array into sheet
    End Sub 
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by kvsrinivasamurthy View Post
    Formula. ARRAY formula In G6 copied to full range
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    VBA code:
    Please Login or Register  to view this content.
    To enter ARRAY formula
    Copy and paste the formula in cell
    Press F2
    Press Ctrl+Shift+Enter together
    Excel covers the formula with {}.
    Hello kvsrinivasamurthy, both VBA & Formula options worked great! Also it results fine with my both versions 2000 & 2010.

    I appreciate your help and time you took for solving my query.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  22. #22
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,018

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by Motilulla View Post
    Hello AliGW, yes if I compare with first post your formula does give the result as request that is perfect! But later I realize my error and corrected that in #post7, I think you did not see that that has create the confusion I am sorry I agree your formula is working fine with opening post.
    Then why didn't you post more realistic sample data at the outset? Hopefully you will learn from this.

  23. #23
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,008

    Re: Count matching data Vertical verses Horizontal values.

    You are welcome.
    -----------------------------------
    If that takes care of your original question, please click on "Thread Tools" from the menu link above and mark this thread as SOLVED.

  24. #24
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by AliGW View Post
    Then why didn't you post more realistic sample data at the outset? Hopefully you will learn from this.
    Hello AliGW, yes sure I will thank you.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  25. #25
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by bebo021999 View Post
    Nice to hear it works.
    And here is VBA solution. Click the button "RUN" to run the code.
    PHP Code: 
    Option Explicit
    Sub matching
    ()
    Dim i&, j&, k&, t&, VTableHTablerngres()
    VTable Range("A6").CurrentRegion.Value ' This is left table (Vertical)
    HTable = Range("G1").CurrentRegion.Value ' 
    This is top table (Horrizontal)
    ReDim res(1 To UBound(VTable), 1 To UBound(HTable2)) ' result array

    '
    Loop thru each single cell in result array, then
    For 1 To UBound(res)
        For 
    1 To UBound(res2)
            
    0
            
            
    'compare each cell in VTable vs HTable, then count the "matching" (k)
            For t = 1 To UBound(VTable, 2)
                If VTable(i, t) = HTable(t, j) Then k = k + 1
            Next
            If k > 2 Then res(i, j) = k ' 
    save the "count" into result range
        Next
    Next
    Range
    ("G6").Resize(UBound(res), UBound(res2)).Value res ' paste the array into sheet
    End Sub 
    Hello bebo021999, VBA also operated spot on! And thank you for adding additional notes in the VBA which field and where to change ranges as required.

    I appreciate your help and time you took for solving this request.

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

  26. #26
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    390

    Re: Count matching data Vertical verses Horizontal values.

    Quote Originally Posted by windknife View Post
    You are welcome.
    -----------------------------------
    If that takes care of your original question, please click on "Thread Tools" from the menu link above and mark this thread as SOLVED.
    Hello windknife, it is done!

    Have a nice day and Good Luck

    Thanks and regards,
    Moti

+ 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] Help required on a Vertical and Horizontal lookup matching criterias
    By stephboucher67 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-29-2022, 07:11 AM
  2. Horizontal and Vertical matching together
    By pmagicnet in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2015, 10:40 AM
  3. [SOLVED] Matching multiple criteria in two books, one data is horizontal, the other is vertical.
    By udrmichelle in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-18-2015, 04:58 PM
  4. [SOLVED] 3 criteria for horizontal and vertical matching
    By mator in forum Excel General
    Replies: 5
    Last Post: 12-24-2014, 07:19 AM
  5. 3 criteria for horizontal and vertical matching from a table
    By mator in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-24-2014, 06:28 AM
  6. Transposing repeating vertical data to horizontal data but retaining unique values only
    By mgcarino14 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 12:57 AM
  7. Replies: 6
    Last Post: 11-20-2011, 06:15 AM

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