SamirBhowmik
New Member
- Joined
- Sep 23, 2021
- Messages
- 26
- Office Version
- 365
- 2013
- Platform
- Windows
Can anyone help me with the below piece of code:
Private Sub UserForm_Initialize()
Dim mylist As Collection
Dim myrng As Range
Dim ws As Worksheet
Dim myval As Variant
Set ws = ThisWorkbook.Sheets("MDB")
Set myrng = ws.Range("A2", ws.Range("A2").End(xlDown))
Set mylist = New Collection
On Error Resume Next
For Each mycell In myrng.Cells
mylist.Add mycell.Value, CStr(mycell.Value)
Next mycell
On Error GoTo 0
For Each myval In mylist
Me.ListBox1.AddItem myval
Next myval
End Sub
This code populates my first listbox with unique items from column A from a table. I have couple of other listboxes where I want to refer to other columns and populate the unique values. I am a newbi in vba so any assistance with explanation will be really appreciated
Private Sub UserForm_Initialize()
Dim mylist As Collection
Dim myrng As Range
Dim ws As Worksheet
Dim myval As Variant
Set ws = ThisWorkbook.Sheets("MDB")
Set myrng = ws.Range("A2", ws.Range("A2").End(xlDown))
Set mylist = New Collection
On Error Resume Next
For Each mycell In myrng.Cells
mylist.Add mycell.Value, CStr(mycell.Value)
Next mycell
On Error GoTo 0
For Each myval In mylist
Me.ListBox1.AddItem myval
Next myval
End Sub
This code populates my first listbox with unique items from column A from a table. I have couple of other listboxes where I want to refer to other columns and populate the unique values. I am a newbi in vba so any assistance with explanation will be really appreciated