Combinations Question

chuckjitsu

New Member
Joined
Apr 24, 2015
Messages
48
Office Version
  1. 365
  2. 2016
Good morning (or afternoon or evening, depending on where you are!). I searched here, but couldn't seem to find a specific answer to what I'm looking for, so if someone knows of a link and can provide it, that would be great. I'm also good with either a VBA solution or worksheet based solution if somebody can do that relatively quickly/easily.

I have four columns, A-D, and each column can contain a value from 1 to 8, meaning the total number of combinations would be 8^4, or 4096. The combination output would look like the below:

1111
1112
1113
etc., with the last value presumably being
8888

Thanks in advance for any assistance.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:

Book1
ABCDEFGHI
111111111
211121112
311131113
411141114
511151115
611161116
711171117
811181118
911211121
1011221122
1111231123
1211241124
1311251125
1411261126
1511271127
1611281128
1711311131
1811321132
Sheet32
Cell Formulas
RangeFormula
A1:D4096A1=MID(BASE(SEQUENCE(4096,,0),8,4),{1,2,3,4},1)+1
F1:I18F1=MID(BASE(ROW()-1,8,4),COLUMNS($F:F),1)+1
Dynamic array formulas.


The A1 formula requires Excel 365, the F1 formula should work in Excel 2013 and newer.
 
Upvote 0
Solution
That was simpler than I thought it would be. The code below worked fine.

VBA Code:
Sub combos()

Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim counter As Integer
Application.ScreenUpdating = False

counter = 0

For A = 1 To 8
For B = 1 To 8
For C = 1 To 8
For D = 1 To 8
counter = counter + 1
Cells(counter, 1) = A
Cells(counter, 2) = B
Cells(counter, 3) = C
Cells(counter, 4) = D
Next D
Next C
Next B
Next A

Application.ScreenUpdating = True


End Sub
 
Upvote 0
Try:

Book1
ABCDEFGHI
111111111
211121112
311131113
411141114
511151115
611161116
711171117
811181118
911211121
1011221122
1111231123
1211241124
1311251125
1411261126
1511271127
1611281128
1711311131
1811321132
Sheet32
Cell Formulas
RangeFormula
A1:D4096A1=MID(BASE(SEQUENCE(4096,,0),8,4),{1,2,3,4},1)+1
F1:I18F1=MID(BASE(ROW()-1,8,4),COLUMNS($F:F),1)+1
Dynamic array formulas.


The A1 formula requires Excel 365, the F1 formula should work in Excel 2013 and newer.


Try:

Book1
ABCDEFGHI
111111111
211121112
311131113
411141114
511151115
611161116
711171117
811181118
911211121
1011221122
1111231123
1211241124
1311251125
1411261126
1511271127
1611281128
1711311131
1811321132
Sheet32
Cell Formulas
RangeFormula
A1:D4096A1=MID(BASE(SEQUENCE(4096,,0),8,4),{1,2,3,4},1)+1
F1:I18F1=MID(BASE(ROW()-1,8,4),COLUMNS($F:F),1)+1
Dynamic array formulas.


The A1 formula requires Excel 365, the F1 formula should work in Excel 2013 and newer.
Hi Eric. I tried your solution but I must be doing something wrong as I got different results. Here's what I did.

Selected A1:D4096
Inserted your formula in the formula bar
selected Ctrl+Shift+Enter

this gave me
1111 for 512 rows
2222 for 512 rows
3333 for 512 rows
etc to
8888 for 512 rows
 
Upvote 0
Which of the two formulae are you talking about?
 
Upvote 0
In that case delete all those cells & then just put the formula into A1 & drag across to D1. Do not fill down & do not use Ctrl Shift Enter.
 
Upvote 0
Apologies, hadn't noticed that Eric had change the formula in A1, do not drag it across, just put it in A1 only as a normal formula
 
Upvote 0
Try:

Book1
ABCDEFGHI
111111111
211121112
311131113
411141114
511151115
611161116
711171117
811181118
911211121
1011221122
1111231123
1211241124
1311251125
1411261126
1511271127
1611281128
1711311131
1811321132
Sheet32
Cell Formulas
RangeFormula
A1:D4096A1=MID(BASE(SEQUENCE(4096,,0),8,4),{1,2,3,4},1)+1
F1:I18F1=MID(BASE(ROW()-1,8,4),COLUMNS($F:F),1)+1
Dynamic array formulas.


The A1 formula requires Excel 365, the F1 formula should work in Excel 2013 and newer.
Thanks Eric! I went with your first formula and got it working with an assist from Fluff. Works great!
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,645
Members
449,461
Latest member
kokoanutt

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