Consulting

Results 1 to 17 of 17

Thread: Count maximum specific combinations between 12 columns

  1. #1
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location

    Count maximum specific combinations between 12 columns

    Hello to everyone,

    I was wondering if someone can help me with a problem I am facing. I would like to analyse a list of values and get the maximum apperance of 2,3,4,5,6,7 and 8 combinations. I have attached a sheet example for better understanding.

    I have been trying to fnd a solution to this problem for a few days now which in turn led me to this forum.

    Thank you in advance for your time,

    Sans
    Attached Files Attached Files

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Your example data is 9 columns, your "sample of actual data" is 12 columns.

    Can we assume that we are always dealing with 12 or fewer columns?

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Welcome to VBAX
    Give this a try
    [VBA]Option Explicit
    Option Base 1
    Sub Test()
    Dim r As Range, c As Range, tgt As Range
    Dim i As Long, j As Long, Chk As Long, rw As Long, cl As Long
    Dim arr(), fmla As String
    Dim x, y, combo As Long
    Dim Tck As String

    Set r = Range("E14:E22")
    Set tgt = Range("O14")
    For i = 1 To 9

    For j = 1 To 9
    If j <> i Then
    fmla = "=SUMPRODUCT(--(" & r.Offset(, i).Address & "=F9),--(" & r.Offset(, j).Address & "=F9))"
    combo = Evaluate(fmla)
    If combo > 1 Then
    If InStr(1, tgt.Offset(, 2 * combo), i) = 0 Then
    tgt.Offset(, 2 * combo) = tgt.Offset(, 2 * combo) & i & ","
    tgt.Offset(, (2 * combo) + 1) = combo
    End If
    End If
    End If
    Next
    Next
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Forgot so say: I put a Tick in F9 to use in the SumProduct function
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    Thank you both very much for your replies.

    Yes the columns in the actual data I will be analysing are 12. If it is possible for the code to function in either 12 or more columns it will be even better. If not, there is no problem. I can mix and match the columns later on.

    Thank you,
    Sans

  6. #6
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    mdmackillop, thank you for your code, I have just tried it and I got a mix of correct and incorrect results. I am preparing now an example which I think is a little more clear on what the results should be. Thank you, Sans

  7. #7
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    I am attaching another smaller example with only 4 columns which is a little more clearer.

    Thank you for your time and help,
    Sans
    Attached Files Attached Files

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your sample is too simple and the logic is not clear to me.. Can you show results for 1,3, ticked, also 3,4 & 1,2,4
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    Not a problem. I'll make a little more complex example now. Thank you for your help, Sans

  10. #10
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    I am attaching another example which is a little more complex. Thank you again,Sans
    Attached Files Attached Files

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A bit rough, but give this a try
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    Thank you.

    I am attaching the same workbook back with some notes. I don't know if the notes convey correctly what I mean. Please let me know if I am being vague in any way.

    Thank you again for your time and help,
    Sans
    Attached Files Attached Files

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This corrects the totals found. There are multiple 5 & 6 tick results with maximum value. Which columns are to be listed?
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #14
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    Thank you for your reply,
    I am attaching back the workbook, with some notes. If for instance there is more than one max combination of 5 checkmarks, they can be listed under each other i.e.

    1,2,4,9,10
    1,2,8,9,12

    Thank you,
    Sans

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With each step this gets more complicated. This is beyond the scope I consider as free assistance as per our FAQ
    Hopefully you can work out a solution.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    VBAX Regular
    Joined
    Nov 2011
    Posts
    21
    Location
    That's ok, thank you very much for your time and effort,Sans

  17. #17
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    The array UDF in the attached will do what you want, albeit slowly.

    This could be improved.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •