Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:02:02+00:00 2026-06-13T09:02:02+00:00

I am layering, stacking my options in excel. I have asked the question in

  • 0

I am layering, stacking my options in excel. I have asked the question in a similar way, however I now want to put some more detail into it. If I have n number of boxes to stack, the possible options to stack them is 2^n-1. Let me give an example of 3 boxes and we give them the names A, B, C and D. The way they are stacked does not matter, meaning AB=BA and ABC=CAB, they count as 1 stack option. The result would be:

A, B, C, AB, BC, AC, ABC

Now I would like to create an excel file which in which I will enter the boxes letters and it gives me a list of all the possibilities for stacking. So I would provide the number of boxes and the letters. (3 boxes, A, B, C) Excel reads this in and gives me in cells the options.

Is it possible to get the options in a row underneath each other? for n number of boxes?

Is this possible? Can anyone help me with this?

Thank you in advanced!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:02:03+00:00Added an answer on June 13, 2026 at 9:02 am

    Some Code modified from Tony Dallimore’s post on Creating a list of all possible unique combinations from an array (using VBA)

    usage:

    1. in Macro “stackBox” — change “Sheet1” to the worksheet name you
      want

    2. input the Number of boxes in cell A1

    3. input the name in B1, C1, … and so on ..

    4. call stackBox

    Input Format & Output result in “Sheet1”:

    3   A   B   C   D   E
    A                   
    B                   
    AB                  
    C                   
    AC                  
    BC                  
    ABC                 
    D                   
    AD                  
    BD                  
    ABD                 
    CD                  
    ACD                 
    BCD                 
    E                   
    AE                  
    BE                  
    ABE                 
    CE                  
    ACE                 
    BCE                 
    DE                  
    ADE                 
    BDE                 
    CDE 
    

    The code:

     Function stackBox()
        Dim ws As Worksheet
        Dim width As Long
        Dim height As Long
        Dim numOfBox As Long
        Dim optionsA() As Variant
        Dim results() As Variant
        Dim str As String
        Dim outputArray As Variant
        Dim i As Long, j As Long
        Set ws = Worksheets("Sheet1")
        With ws
            'clear last time's output
            height = .Cells(.Rows.Count, 1).End(xlUp).row
            If height > 1 Then
                .Range(.Cells(2, 1), .Cells(height, 1)).ClearContents
            End If
    
            numOfBox = .Cells(1, 1).Value
            width = .Cells(1, .Columns.Count).End(xlToLeft).Column
            If width < 2 Then
                MsgBox "Error: There's no item, please fill your item in Cell B1,C1,..."
                Exit Function
            End If
            ReDim optionsA(0 To width - 2)
            For i = 0 To width - 2
                optionsA(i) = .Cells(1, i + 2).Value
            Next i
    
            GenerateCombinations optionsA, results, numOfBox
    
    
            ' copy the result to sheet only once
            ReDim outputArray(1 To UBound(results, 1) - LBound(results, 1) + 1, 1 To 1)
            Count = 0
            For i = LBound(results, 1) To UBound(results, 1)
                If Not IsEmpty(results(i)) Then
                    'rowNum = rowNum + 1
                    str = ""
    
                    For j = LBound(results(i), 1) To UBound(results(i), 1)
                        str = str & results(i)(j)
                    Next j
                    Count = Count + 1
                    outputArray(Count, 1) = str
                '.Cells(rowNum, 1).Value = str
                End If
            Next i
            .Range(.Cells(2, 1), .Cells(UBound(outputArray, 1) + 1, 1)).Value = outputArray
        End With
    
    End Function
    
    Sub GenerateCombinations(ByRef AllFields() As Variant, _
                                                 ByRef Result() As Variant, ByVal numOfBox As Long)
    
      Dim InxResultCrnt As Integer
      Dim InxField As Integer
      Dim InxResult As Integer
      Dim i As Integer
      Dim NumFields As Integer
      Dim Powers() As Integer
      Dim ResultCrnt() As String
    
      NumFields = UBound(AllFields) - LBound(AllFields) + 1
    
      ReDim Result(0 To 2 ^ NumFields - 2)  ' one entry per combination
      ReDim Powers(0 To NumFields - 1)          ' one entry per field name
    
      ' Generate powers used for extracting bits from InxResult
      For InxField = 0 To NumFields - 1
        Powers(InxField) = 2 ^ InxField
      Next
    
     For InxResult = 0 To 2 ^ NumFields - 2
        ' Size ResultCrnt to the max number of fields per combination
        ' Build this loop's combination in ResultCrnt
    
        ReDim ResultCrnt(0 To NumFields - 1)
        InxResultCrnt = -1
        For InxField = 0 To NumFields - 1
          If ((InxResult + 1) And Powers(InxField)) <> 0 Then
            ' This field required in this combination
            InxResultCrnt = InxResultCrnt + 1
            ResultCrnt(InxResultCrnt) = AllFields(InxField)
          End If
        Next
    
        If InxResultCrnt = 0 Then
            Debug.Print "testing"
        End If
        'additional logic here
        If InxResultCrnt >= numOfBox Then
            Result(InxResult) = Empty
    
        Else
             ' Discard unused trailing entries
            ReDim Preserve ResultCrnt(0 To InxResultCrnt)
            ' Store this loop's combination in return array
            Result(InxResult) = ResultCrnt
        End If
    
      Next
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some help on this website I am now looking for more. This was
I have some code as follows where I think my layering is causing a
I'm trying to create a watermark with ImageMagick however, the guides on layering are
I have a complex layering situation for the website: http://andstones.ca/contact/ where I use a
I want to implement a layering system in my application and was thinking of
I'm writing an eclipse plugin, and I'm layering some simple figures (i.e. view elements)
I have a list of divs that I want to be able to sort.
I know some DI frameworks support this (e.g. Ninject ), but I specifically want
I want to implement layering of screens when transitioning from one screen to another.
I am having trouble understanding how layering is performed within Xcode. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.