Excel permutations of columns VBA required

colink2

New Member
Joined
Apr 15, 2020
Messages
9
Office Version
  1. 2010
Platform
  1. Windows
Hi

I had a fully working Excel workbook that I found from an online tutorial, but the woorkbook has lost it's VBA code somehow.

I have spent a lot of time online looking again including this forum, but could not find exactly what I need.

If anyone could provide necessary code or point me to a turorial I would appreciate it.

It allowed user to enter data into any number of columns (I only need three).

Running the macro created three new columns to the right with all possible permutations - no duplicates.

see image.

Thanks ColinK2
excel-column-permutations.jpg
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi and welcome to MrExcel!

For 3 columns try this:

VBA Code:
Sub permutations_columns()
  Dim i As Long, j As Long, k As Long, n As Long
  For i = 1 To Range("A" & Rows.Count).End(3).Row
    For j = 1 To Range("B" & Rows.Count).End(3).Row
      For k = 1 To Range("C" & Rows.Count).End(3).Row
        Range("E" & Rows.Count).End(3)(2).Resize(1, 3).Value = Array(Range("A" & i), Range("B" & j), Range("C" & k))
      Next
    Next
  Next
End Sub
 
Upvote 0
Hi and welcome to MrExcel!

Fantastic. I really appreciate your prompt response.

This does exactly what I want for my current project.

I posted this question at 1am before going to bed and had my answer when I logged on this morning.

I am a "copy and paste" coder but think I could even mange to edit the code for additional columns.
=====
If anyone finds code which automatically deals with multiple columns that are not defined in the code it would be good if they could reply with details. Even if that does nto happen I am more than happy with the great help I received from @DanteAmor
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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