vendredi 27 février 2015

Populate a list box with a dynamic list in vba

I am trying to populate a list box with the a list of dynamic length from another sheet. I want to eventually be able to select multiple items from this list box to trigger some vlookups and further calculations.


However, I am unsure of how to populate the listbox with my list. When I run/step through the following code I do not get any error messages but it does not populate the box



Sub FilterUniqueData()
Dim Lrow As Long, test As New Collection
Dim Value As Variant, temp() As Variant
ReDim temp(0)
Dim Value1 As Variant

On Error Resume Next
With Workbooks("Copy of SWR1304 (Future Development Risk Assessment) Strathaven.xls").Sheets("Non Household Metered Users")
Lrow = .Range("h" & Rows.Count).End(xlUp).Row
temp = .Range("h12:h" & Lrow).Value
End With

For Each Value In temp
If Len(Value) > 0 Then test.Add Value, CStr(Value)
Next Value

ReDim temp(0)
Workbooks("DMA_metered_tool").Worksheets("DMA list").Shapes("List Box 2").ControlFormat.RemoveAllItems

For Each Value In test
Worksheets("DMA list").Shapes("List Box 2").ControlFormat.AddItem Value
Next Value

Set test = Nothing

End Sub


Any suggestions much appreciated.


Cheers


Aucun commentaire:

Enregistrer un commentaire