Count distinct value pairs in multiple columns

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,
Pairs S5 ToRight
Multiple columns combinations R6 ToDown

Data Columns C:P (P1 To P14)
Cell R6 = 1|2|3|4|5|6|7 mean (P1+P2+P3+P4+P5+P6+P7) count Pairs S5 (1|1|1|1|1|1|1) result S6 = 34
Cell R7 = 1|2|3|4|5|6|8 mean (P1+P2+P3+P4+P5+P6+P8) count Pairs S5 (1|1|1|1|1|1|1) result S7 = 28

Example: I have count using AutoFilter as there are 14 columns so COMBIN(14,7) = 3432 I believe need VBA


Book1
ABCDEFGHIJKLMNOPQRSTU
1JorTempP1P2P3P4P5P6P7P8P9P10P11P12P13P14EM 1
2JorTempP1P2P3P4P5P6P7P8P9P10P11P12P13P14EM 1
3JorTempP1P2P3P4P5P6P7P8P9P10P11P12P13P14EM 1
4JorTempP1P2P3P4P5P6P7P8P9P10P11P12P13P14EM 1MultipleCountsCountsCounts
5JorTemp1234567891011121314EM 1Columns1|1|1|1|1|1|1X|X|2|2|1|2|11|1|1|1|1|1|X
6170/7111111111112XX11|2|3|4|5|6|734110
7270/7111111111112XX11|2|3|4|5|6|8287
8370/71111111212111X11|2|3|4|5|6|92515
9470/711111111112X1XX1|2|3|4|5|6|10289
10570/711111111111X2111|2|3|4|5|6|111922
11670/71111111211X12111|2|3|4|5|6|122214
12770/711111111XX212X11|2|3|4|5|6|131215
13870/71111111X11121121|2|3|4|5|6|142613
14970/71111111X1XX222X1|2|3|4|5|7|8
151070/71111111X12111211|2|3|4|5|7|9
161170/711111111X111X121|2|3|4|5|7|10
171270/7111111112X121221|2|3|4|5|7|11
181370/711111111XXX21X21|2|3|4|5|7|12
191470/711111112111X2111|2|3|4|5|7|13
201570/71111111X111X1221|2|3|4|5|7|14
211670/7111111112X21X1X1|2|3|4|5|8|9
221770/711111111111XXXX1|2|3|4|5|8|10
231870/71111111X11XXX111|2|3|4|5|8|11
241970/711111111111XXXX1|2|3|4|5|8|12
252070/7111111111X111211|2|3|4|5|8|13
262170/711111111X1XXX211|2|3|4|5|8|14
272270/7111111111X111211|2|3|4|5|9|10
282370/71111111112111211|2|3|4|5|9|11
292470/711111111112X11X1|2|3|4|5|9|12
302570/7111111111X2122X1|2|3|4|5|9|13
312670/7111111111X1XX221|2|3|4|5|9|14
322770/71111111X11X12211|2|3|4|5|10|11
332870/7111111111X2X2211|2|3|4|5|10|12
342970/7111111111X2122X1|2|3|4|5|10|13
353070/7111111111X1XX221|2|3|4|5|10|14
363170/71111111X11XXX111|2|3|4|5|11|12
373270/711111111111XXXX1|2|3|4|5|11|13
383370/7111111111X111211|2|3|4|5|11|14
393470/7111111112X11X2X1|2|3|4|5|12|13
403570/71111111112111X11|2|3|4|5|12|14
413670/71111111211X22211|2|3|4|5|13|14
423770/71111111112111211|2|3|4|6|7|8
433870/711111111112X11X1|2|3|4|6|7|9
443970/711111111X111X121|2|3|4|6|7|10
454070/711111111X1X11221|2|3|4|6|7|11
46171/721111111112X1XX1|2|3|4|6|7|12
47271/721111111111X2111|2|3|4|6|7|13
48371/72111111112111X11|2|3|4|6|7|14
49471/721111111X21X1X11|2|3|4|6|8|9
50571/72111111X112X1XX1|2|3|4|6|8|10
51671/72111111X121X1X11|2|3|4|6|8|11
52771/7211111111X2X2211|2|3|4|6|8|12
53871/72111111X111X1211|2|3|4|6|8|13
54971/7221X21XXX1XX12X1|2|3|4|6|8|14
551071/72XX21X1121121211|2|3|4|6|9|10
561171/721X2X1212XX112X1|2|3|4|6|9|11
571271/72X2X11111121XXX1|2|3|4|6|9|12
581371/7211X11X11XX11111|2|3|4|6|9|13
591471/7211X111X11111111|2|3|4|6|9|14
601571/7221X111211XXX1X1|2|3|4|6|10|11
611671/72X122X11X1111111|2|3|4|6|10|12
621771/722111221122XX121|2|3|4|6|10|13
631871/72111211111X21111|2|3|4|6|10|14
641971/721X21X1121X221X1|2|3|4|6|11|12
652071/721X1X11XX111X111|2|3|4|6|11|13
662171/72XXX111111111111|2|3|4|6|11|14
672271/72XX22121X11X12X1|2|3|4|6|12|13
682371/7211211111X111111|2|3|4|6|12|14
692471/72X111X1121121XX1|2|3|4|6|13|14
702571/721112X1X11X1XX11|2|3|4|7|8|9
712671/721X1112X1XXX21X1|2|3|4|7|8|10
722771/7211X1XXX111X12X1|2|3|4|7|8|11
732871/721X1X1X22X111121|2|3|4|7|8|12
742971/7211X22111X111121|2|3|4|7|8|13
753071/721XX1X11121111X1|2|3|4|7|8|14
763171/721XXXX1211111211|2|3|4|7|9|10
773271/722X1X111112X1221|2|3|4|7|9|11
783371/7211X122211X1XX21|2|3|4|7|9|12
793471/721111X111111XX11|2|3|4|7|9|13
803571/72111121X11X11111|2|3|4|7|9|14
813671/722X2X121X1X1XX11|2|3|4|7|10|11
823771/7221X111112X111X1|2|3|4|7|10|12
833871/721111X1X12111X21|2|3|4|7|10|13
84172/73X1212XX112X1121|2|3|4|7|10|14
85272/731X2221XX22XX111|2|3|4|7|11|12
86372/731X11XX22XX11XX1|2|3|4|7|11|13
87472/731X1221X11X12211|2|3|4|7|11|14
88572/73X1X1X11X111XX11|2|3|4|7|12|13
89672/73XXX1111X1X212X1|2|3|4|7|12|14
90772/732X1112XXX111211|2|3|4|7|13|14
Sheet1


Thank you in advance

Regards,
Kishan
 
Hi Ombir, thank you for your kind help I appreciate your help very much, I am sorry for the trouble and hassle that I have caused you.

I tried both code are in Post#18 & Post#20, they stop at the line below.

Post#18
Code:
nar(i) = Join(Application.Index(arr, i, 0), "|")

Post#20
Code:
 nar(i) = Join(Application.Index(arr, i, 0), "|")

Please can you check?

Kind Regards,
Kishan
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
See if this modified version of the code I posted earlier works for you...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub PatternCounts()
  Dim R As Long, C As Long, X As Long, Z As Long, Cnt As Long
  Dim Pattern As String, Lines(1 To 14) As String
  Dim Data As Variant, Results As Variant
  Data = Range("C6", Cells(Rows.Count, "P").End(xlUp))
  Results = Range("R5", Cells(Cells(Rows.Count, "R").End(xlUp).Row, Cells(5, Columns.Count).End(xlToLeft).Column))
  For R = 2 To UBound(Results, 1)
    For X = 1 To UBound(Data)
      For Z = 1 To 14
        Lines(Z) = Data(X, Z)
      Next
      Pattern = Join(Application.Index(Lines, 1, Split(Results(R, 1), "|")), "|")
      For C = 2 To UBound(Results, 2)
        If Pattern = Results(1, C) Then Results(R, C) = Results(R, C) + 1
      Next
    Next
  Next
  Range("R5").Resize(UBound(Results, 1), UBound(Results, 2)) = Results
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
Thank you Rick, Your help means a lot to me. I am grateful to you for making a modification to work with my version. I am sorry for the trouble and hassle that I have caused you.

Above modified code, which is working with my full database like magic.
Problem Solved!!

Good Luck

Have a nice weekend

Kind Regards,
Kishan :)
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,107
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top