The other day someone already helped a great deal with adjusting this code but I have to add a condition now that is not creating the combination, but has to make sure that Column B, D and F only mix when the value in Column A, C and E are matching each other. Let me show you what I mean:
Region 1 | Item 1 | Region 2 | Item 2 | Region 3 | Item 3 |
---|---|---|---|---|---|
EMEA | ABC | EMEA | 123 | US | one |
US | DEF | US | 456 | EMEA | two |
The end result should therefore be as follows:
- ABC-123-two
- DEF-456-one
I tried to set something up in the current code but failed and removed it from the code. Ideally what needs to happen is that it first ignores any empty value in the range and then checks if the region is equal to the region in the second item or third item.
Here is the VBA, any advice would be very much appreciated. Thanks in advance:
Sub CombinationGenerator()
Dim xDRg1 As Range, xDRg2 As Range, xDRg3 As Range
Dim xRg As Range
Dim xStr As String
Dim xFN1 As Range, xFN2 As Range, xFN3 As Range
Dim xSV1 As String, xSV2 As String, xSV3 As String
Set xDRg1 = Range("B2:B75") 'First column combintation data
Set xDRg2 = Range("D2:D75") 'Second column combintation data
Set xDRg3 = Range("F2:F75") 'Third column combintation data
xStr = "-" 'Separator
Set xRg = Range("I2") 'Output cell
'Creating combinations
For Each xFN1 In xDRg1.Cells
If xFN1 <> "" Then 'Ignore empty cells
xSV1 = xFN1.Text
For Each xFN2 In xDRg2.Cells
If xFN2 <> "" Then 'Ignore empty cells
xSV2 = xFN2.Text
For Each xFN3 In xDRg3.Cells
If xFN3 <> "" Then 'Ignore empty cells
xSV3 = xFN3.Text
xRg.Value = xSV1 & xStr & xSV2 & xStr & xSV3
Set xRg = xRg.Offset(1, 0)
End If
Next
End If
Next
End If
Next
End Sub