+ Reply to Thread
Results 1 to 2 of 2

Combination algorithm VBA

  1. #1
    Registered User
    Join Date
    08-29-2016
    Location
    Singapore
    MS-Off Ver
    2007
    Posts
    41

    Combination algorithm VBA

    Dear all

    Is it possible to have an excel VBA for combination generator?

    I saw this in the following website but there is a limitation for displaying more than 5000 results.

    https://www.dcode.fr/combinations

    Example:

    I have 5 options (n = 5)

    a
    b
    c
    d
    e

    I want to generate combinations of 3 (k = 3). The results will be

    a b c
    a b d
    a b e
    a c d
    a c e
    a d e
    b c d
    b c e
    b d e
    c d e

    I have a project with 20 options and I need to list down all the possible combinations of choosing k out 20 e.g. 15 out of 20 options.

    Really appreciate if someone could assist.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration ‼


    As a VBA starter :

    PHP Code: 
    Const 3

    Dim R
    &, VW(), XY(1 To K)

    Sub Combinate(Optional C& = 1Optional P& = 1)
        For 
    P To X(C)
            
    Y(C) = V(P)
            If 
    K Then Combinate C 1Else 1W(R) = Y
        Next
    End Sub

    Sub Demo1
    ()
        
    Dim N&
        
    ActiveSheet.UsedRange.Clear
        V 
    = [{"a","b","c","d","e"}]
        
    UBound(V):  If <= K Then Beep: Exit Sub
        ReDim W
    (1 To Evaluate("COMBIN(" "," ")"))
        
    0
        X 
    Evaluate("COLUMN(" Cells(1).Resize(, K).Address ")")
        
    Combinate
        X 
    Evaluate("COLUMN(" Cells(1).Resize(, K).Address ")")
        [
    A1].Resize(RK) = Application.Index(WEvaluate("ROW(1:" ")"), X)
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

+ 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] How to make the combination of numbers and total of that combination should be in range?
    By Darshan Shah in forum Excel Programming / VBA / Macros
    Replies: 38
    Last Post: 06-20-2020, 01:20 PM
  2. VBA Algorithm Help Please
    By steveyh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2019, 10:01 AM
  3. Combination algorithm for this condition
    By sleepwalker49 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2018, 10:48 AM
  4. [SOLVED] how many cell in a row that contain certain combination from a larger combination
    By system in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 11-17-2012, 03:04 PM
  5. algorithm help
    By david90 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-30-2012, 10:33 AM
  6. WAP for given algorithm
    By newguy59 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2011, 07:11 AM
  7. [SOLVED] Algorithm Challenge
    By Lowkey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

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