Combination macro

k.03a

New Member
Joined
Jul 12, 2011
Messages
19
Hi everyone, I'm looking for a combination macro and can't find what I need. Unfortunately I'm also a VBA newbie.

The simplified version goes like this: I have a list of items in rows A and B
A B
x x
y y
z z

And I want the list of all combinations in column C
C
x-x
x-y
x-z
y-x
etc...

the problem is the list of items is unknown in length, and contains about 150 different items.


The full version of the problem is a bit more complex because I want to avoid repetitions. For example

A B
x x
x x
z z

would return
C
x-x
x-z
z-x
z-z

Can anyone help?

Thanks a lot !
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Not a pretty solution, but:
Code:
Sub Combination()
 
    Dim lr As Long, lr2 As Long, i As Long, n As Long, cRow As Long
 
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lr2 = Range("B" & Rows.Count).End(xlUp).Row
    cRow = 2
 
    For i = 2 To lr
        For n = 2 To lr2
            If Application.WorksheetFunction.CountIf(Range("C2:C" & cRow), Range("A" & i).Value & "-" & Range("B" & n).Value) = 0 Then
                Range("C" & cRow).Value = Range("A" & i).Value & "-" & Range("B" & n).Value
                cRow = cRow + 1
            End If
        Next n
    Next i
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,214
Members
452,895
Latest member
BILLING GUY

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