Getting Unique Combinations of Two or More Fields

To get all unique combinations of two (or more) fields, build the output range to include the additional fields. This code sample builds a list of unique combinations of two fields; Customer and Product:

Sub UniqueCustomerProduct() Dim IRange As Range Dim ORange As Range

' Find the size of today's dataset FinalRow = Cells(65536, 1).End(xlUp).Row NextCol = Cells(1, 255).End(xlToLeft).Column + 2

1 Set up output range. Copy headings from D1 & B1 Range("D1").Copy Destination:=Cells(1, NextCol) Range("B1").Copy Destination:=Cells(1, NextCol + 1) Set ORange = Cells(1, NextCol).Resize(1, 2)

0 0

Post a comment