Results 1 to 4 of 4

Thread: Formula For all possible product combinations

  1. #1

    Formula For all possible product combinations



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I need an excel spreadsheet to give me all my possible product model
    numbers, with the various options included. Please see the attached
    spreadsheet for an example. I hope i have explained it well enough.
    Attached Files Attached Files

  2. #2
    This is becoming kind of urgent, is there nobdy that can help me?

  3. #3
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,021
    Articles
    79
    Blog Entries
    14
    The attached example file uses VBA to do it.

    Commented code as follows:
    Code:
    Sub Possibilities()
        Dim sModel As String
        Dim cl As Range
        Dim rngModels As Range
        Dim rngCatA As Range
        Dim lClean As Long
        Dim lColA As Long
        Dim lColB As Long
        Dim lColC As Long
        Dim lColD As Long
        With Worksheets("Sheet1")
            'Range of model numbers to prepend
            Set rngModels = .Range("A2:A3")
            
            'First cell in data table
            Set rngCatA = .Range("B8")
            
            'Set up target list area
            .Range("B16:B" & .Range("B" & .Rows.Count).End(xlUp).Row).ClearContents
            .Range("B16").Value = "Model Number"
            'Create possibilities
            For Each cl In rngModels
                For lColA = 0 To 3
                    For lColB = 0 To 3
                        For lColC = 0 To 3
                            For lColD = 0 To 3
                                'Generate raw possibilities
                                sModel = cl.Value & "/" & _
                                         rngCatA.Offset(lColA, 0) & "/" & _
                                         rngCatA.Offset(lColB, 1) & "/" & _
                                         rngCatA.Offset(lColC, 2) & "/" & _
                                         rngCatA.Offset(lColD, 3)
                                      
                                'Strip any instances of // (from blank quartets)
                                For lClean = 1 To 4
                                    sModel = Replace(sModel, "//", "/")
                                Next lClean
                                
                                'Remove trailing / if necessary (blank final quartet)
                                If Right(sModel, 1) = "/" Then sModel = Left(sModel, Len(sModel) - 1)
                                
                                'Place value in cell
                                .Range("B" & .Range("B" & .Rows.Count).End(xlUp).Row).Offset(1, 0).Value = sModel
                            Next lColD
                        Next lColC
                    Next lColB
                Next lColA
            Next cl
        End With
    End Sub
    Attached Files Attached Files
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Master your data with Power Query: Purchase your copy of my book M is for Data Monkey today!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  4. #4
    Awesome! Thanks.

Posting Permissions

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