austin350s10
Active Member
- Joined
- Jul 30, 2010
- Messages
- 321
I am trying to use the below code to fill a combobox with unique values. It works great except I can't figure out a way to replace BLOCK 1 with BLOCK 2. I want to use BLOCK 2 to populate mgNames so that only specific values are filled into mgNames. Currently BLOCK 1 just fills mgNames with an entire range without any conditions. Anyone have an idea how I can get BLOCK 2 to work in the way i'm intending it to?
Code:
Sub findNames()
Dim mgNames As Variant
Dim myCollection As New Collection
Dim temp As Variant
'so far I can get BLOCK 1 to fill mgNames with a range but I want to fill it with specific values with the condition in BLOCK 2.
'BLOCK 1 start ---------------------------
With ActiveSheet
mgNames = Range(.Cells(2, 4), .Cells(.Rows.Count, 4).End(xlUp)).Value
End With
'BLOCK 1 end ----------------------------
'BLOCK 2 start ---------------------------
For Each c In Range(.Cells(2, 4), .Cells(.Rows.Count, 4).End(xlUp))
If Trim(c.Offset(0, 7).Value) = "Hourly" Then
'looking for a way to fill mgNames with just the cells that meet the condition
End If
Next c
'BLOCK 2 end ----------------------------
On Error Resume Next
For Each temp In mgNames
myCollection.Add Item:=temp, Key:=temp
Next temp
On Error GoTo 0
ReDim mgNames(1 To myCollection.Count)
For temp = 1 To myCollection.Count
mgNames(temp) = myCollection(temp)
Next temp
For temp = LBound(mgNames) To UBound(mgNames)
boxNames.AddItem mgNames(temp)
Next temp
End Sub