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.
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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by AliGW
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.
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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by bebo021999
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.
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.
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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by AliGW
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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by Motilulla
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&, VTable, HTable, rng, res() 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(HTable, 2)) ' result array
'Loop thru each single cell in result array, then For i = 1 To UBound(res) For j = 1 To UBound(res, 2) k = 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(res, 2)).Value = res ' paste the array into sheet End Sub
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.
Originally Posted by Motilulla
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.
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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by bebo021999
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&, VTable, HTable, rng, res() 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(HTable, 2)) ' result array
'Loop thru each single cell in result array, then For i = 1 To UBound(res) For j = 1 To UBound(res, 2) k = 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(res, 2)).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.
Re: Count matching data Vertical verses Horizontal values.
Originally Posted by windknife
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.
Bookmarks