Combining related unique (distinct) values from two columns into an array

C

cmwilliams

Hi,

I need to do the following with VBA and I've run into a mental
stumbling block.

I need to combine related unique values from two columns into an array.

For example

Column A

(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)
(e-mail address removed)

Column B
Text
Text
Text
HTML
HTML
text

So I need the unique e-mail address from Column A along with it's
related value in column B and store that into an array so I can split
it up.

I'm pretty new to Excel programming so any guidance is greatly
appreciated.

I have the following code (which I got from this group) which will get
the unique e-mail addresses but I don't know how to pair them up with
their related values from column B

Function DistinctArray(oInputArray, _
Optional MatchCase As Boolean = True, _
Optional OmitBlanks As Boolean = True)

Dim oOutputArray As Variant
Dim oElement As Variant

Set oDictionary = CreateObject("Scripting.Dictionary")

oDictionary.CompareMode = Abs(Not MatchCase)

For Each oElement In oInputArray
oDictionary.Item(CStr(oElement)) = oElement
Next

If OmitBlanks Then
If oDictionary.Exists("") Then oDictionary.Remove ("")
End If

oOutputArray = oDictionary.Items

DistinctArray = oOutputArray

End Function

======================================================================

Private Sub CommandButton3_Click()

Dim arr1(), arr2()

arr1 = Range("A2:A65536").SpecialCells(xlCellTypeVisible)
arr2 = DistinctArray(arr1)

For intPosition = LBound(arr2) To UBound(arr2)
MsgBox (arr2(intPosition))
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top