VBA Combination Unique Values

Webb_GM_2010

New Member
Joined
Apr 12, 2010
Messages
6
Hello All,

I have a simple VBA code which generates all possible combinations from a list (A, B, C). The code returns all 27 combinations from AAA to CCC. However, I would like to generate ONLY the unique values (so values without repeating the same item). The list of values I want would therefore be only 6.

A B C
A C B
B A C
B C A
C A B
C B A

The code I am currently using is:
Code:
Private Sub Test_Click()

Dim MyArray(2)

MyArray(0) = "A"
MyArray(1) = "B"
MyArray(2) = "C"

r = 2
col = 2


For a = 0 To 2
For b = 0 To 2
For c = 0 To 2

Cells(r, col) = MyArray(a) & MyArray(b) & MyArray(c)

r = r + 1

Next c
Next b
Next a

End Sub

Please can you help incorporate this into the code or write a completely new one.

Thanks for your help!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try

Code:
Sub Test_Click()
Dim MyArray(2)
MyArray(0) = "A"
MyArray(1) = "B"
MyArray(2) = "C"
r = 2
col = 2
For a = 0 To 2
    For b = 0 To 2
        For c = 0 To 2
            If MyArray(a) <> MyArray(b) And MyArray(b) <> MyArray(c) And MyArray(a) <> MyArray(c) Then
                Cells(r, col) = MyArray(a) & MyArray(b) & MyArray(c)
                r = r + 1
            End If
        Next c
    Next b
Next a
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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