I have this list in my "Ref" sheet which is very hidden in column H and I. and have Combobox in sheet "GH & AM Summery" by any change is there a way combobox1 will display unique list from column H and with respect to combobox1 it will display unique list in combbox2.
comboxbox1 will contain grouphead names were as comboxbox2 will contain account manager names.
the code below is not solving the purpose, any suggestions?
sample table
'It is just giving the unique list
comboxbox1 will contain grouphead names were as comboxbox2 will contain account manager names.
the code below is not solving the purpose, any suggestions?
sample table
GROUP HEAD | ACOUNT MANAGER |
A | AB |
A | AC |
A | AD |
A | AE |
A | AF |
A | AG |
B | BA |
B | BC |
B | BD |
C | CA |
D | DA |
D | DB |
D | DC |
D | DD |
'It is just giving the unique list
VBA Code:
Sub GroupHeadCombo()
'Group Head
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim wsSheet1 As Worksheet
Dim rnData As Range
Dim vaData As Variant 'the list, stored in a variant
Dim ncData As New VBA.Collection 'the list, stored in a collection
Dim lnCount As Long 'the count used in the On Error Resume Next loop.
Dim vaItem As Variant 'a variant representing the type of items in ncData
'Instantiate the Excel objects.
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets("Ref")
Set wsSheet1 = wbBook.Worksheets("GH & AM Summery")
'Using Sheet2,retrieve the range of the list in Column A.
With wsSheet
Set rnData = .Range(.Range("H3"), .Range("H100").End(xlUp))
End With
'Place the list values into vaData.
vaData = rnData.Value
'Place the list values from vaData into the VBA.Collection.
On Error Resume Next
For lnCount = 1 To UBound(vaData)
ncData.Add vaData(lnCount, 1), CStr(vaData(lnCount, 1))
Next lnCount
On Error GoTo 0
'Clear the combo box (in case you ran the macro before),
'and then add each unique variant item from ncData to the combo box.
With wsSheet1.OLEObjects("ComboBox1").Object
.Clear
For Each vaItem In ncData
.AddItem ncData(vaItem)
Next vaItem
End With
End Sub