dirty_pencil
New Member
- Joined
- Oct 24, 2018
- Messages
- 6
[FONT="]Hi,[/FONT]
[FONT="]I am trying to create a macro in VBA that takes data from three different columns and creates unique permutations while excluding any rows that have the same value in the first two columns. Example below;[/FONT]
[FONT="]
[/FONT]
[TABLE="class: yklcuq-19 cUmOil"]
<thead style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TH="class: yklcuq-25 kFFvu, align: center"]1[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]1[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]A[/TH]
[/TR]
</thead><tbody style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]2[/TD]
[TD="class: yklcuq-21 gHVYpd"]1[/TD]
[TD="class: yklcuq-21 gHVYpd"]B[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]3[/TD]
[TD="class: yklcuq-21 gHVYpd"]1[/TD]
[TD="class: yklcuq-21 gHVYpd"]C[/TD]
[/TR]
</tbody>[/TABLE]
[FONT="]Unique permutations, excluding duplicate values in columns one and two would be[/FONT]
[FONT="]2-1-A[/FONT]
[FONT="]2-1-B[/FONT]
[FONT="]2-1-C[/FONT]
[FONT="]3-1-A[/FONT]
[FONT="]3-1-B[/FONT]
[FONT="]3-1-C[/FONT]
[FONT="]
[/FONT]
[FONT="]So permutations like 1-1-A would be exclude, since there is a 1 in both columns.[/FONT]
[FONT="]
[/FONT]
[FONT="]Here is the code that I have now that creates the permutations but doesn't exclude the 1-1-A type instances.
[/FONT]
[FONT="]<code class="yklcuq-7 iRRQrr" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: transparent; color: rgb(34, 34, 34); max-width: 100%; overflow: auto;">Sub
Dim c1() As Variant
Dim c2() As Variant
Dim c3() As Variant
Dim out() As Variant
Dim j, k, l, m As Long
Dim col1 As Range
Dim col2 As Range
Dim col3 As Range
Dim out1 As Range
Set col1 = Range("A2", Range("A2").End(xlDown))
Set col2 = Range("B2", Range("B2").End(xlDown))
Set col3 = Range("C2", Range("C2").End(xlDown))
c1 = col1
c2 = col2
c3 = col3
Set out1 = Range("E2", Range("G2").Offset(UBound(c1) * UBound(c2) * UBound(c3)))
out = out1
j = 1
k = 1
l = 1
m = 1
Do While j <= UBound(c1)
Do While k <= UBound(c2)
Do While l <= UBound(c3)
out(m, 1) = c1(j, 1)
out(m, 2) = c2(k, 1)
out(m, 3) = c3(l, 1)
m = m + 1
l = l + 1
Loop
l = 1
k = k + 1
Loop
k = 1
j = j + 1
Loop
out1.Value = out
End Sub
</code>Any ideas?
[/FONT]
[FONT="]I am trying to create a macro in VBA that takes data from three different columns and creates unique permutations while excluding any rows that have the same value in the first two columns. Example below;[/FONT]
[FONT="]
[/FONT]
[TABLE="class: yklcuq-19 cUmOil"]
<thead style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TH="class: yklcuq-25 kFFvu, align: center"]1[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]1[/TH]
[TH="class: yklcuq-25 kFFvu, align: center"]A[/TH]
[/TR]
</thead><tbody style="margin: 0px; padding: 0px; border: 0px; font: inherit; vertical-align: baseline;">[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]2[/TD]
[TD="class: yklcuq-21 gHVYpd"]1[/TD]
[TD="class: yklcuq-21 gHVYpd"]B[/TD]
[/TR]
[TR="class: yklcuq-20 dqbluc, bgcolor: rgba(255, 255, 255, 0.8)"]
[TD="class: yklcuq-21 gHVYpd"]3[/TD]
[TD="class: yklcuq-21 gHVYpd"]1[/TD]
[TD="class: yklcuq-21 gHVYpd"]C[/TD]
[/TR]
</tbody>[/TABLE]
[FONT="]Unique permutations, excluding duplicate values in columns one and two would be[/FONT]
[FONT="]2-1-A[/FONT]
[FONT="]2-1-B[/FONT]
[FONT="]2-1-C[/FONT]
[FONT="]3-1-A[/FONT]
[FONT="]3-1-B[/FONT]
[FONT="]3-1-C[/FONT]
[FONT="]
[/FONT]
[FONT="]So permutations like 1-1-A would be exclude, since there is a 1 in both columns.[/FONT]
[FONT="]
[/FONT]
[FONT="]Here is the code that I have now that creates the permutations but doesn't exclude the 1-1-A type instances.
[/FONT]
[FONT="]<code class="yklcuq-7 iRRQrr" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Consolas, "Courier New", monospace; vertical-align: baseline; background: transparent; color: rgb(34, 34, 34); max-width: 100%; overflow: auto;">Sub
Dim c1() As Variant
Dim c2() As Variant
Dim c3() As Variant
Dim out() As Variant
Dim j, k, l, m As Long
Dim col1 As Range
Dim col2 As Range
Dim col3 As Range
Dim out1 As Range
Set col1 = Range("A2", Range("A2").End(xlDown))
Set col2 = Range("B2", Range("B2").End(xlDown))
Set col3 = Range("C2", Range("C2").End(xlDown))
c1 = col1
c2 = col2
c3 = col3
Set out1 = Range("E2", Range("G2").Offset(UBound(c1) * UBound(c2) * UBound(c3)))
out = out1
j = 1
k = 1
l = 1
m = 1
Do While j <= UBound(c1)
Do While k <= UBound(c2)
Do While l <= UBound(c3)
out(m, 1) = c1(j, 1)
out(m, 2) = c2(k, 1)
out(m, 3) = c3(l, 1)
m = m + 1
l = l + 1
Loop
l = 1
k = k + 1
Loop
k = 1
j = j + 1
Loop
out1.Value = out
End Sub
</code>Any ideas?
[/FONT]