ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combining related unique (distinct) values from two columns into an array (https://www.excelbanter.com/excel-programming/376583-combining-related-unique-distinct-values-two-columns-into-array.html)

[email protected]

Combining related unique (distinct) values from two columns into an array
 
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








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



All times are GMT +1. The time now is 06:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com