使用工作簿上的唯一值填充用户窗体中的列表框
Populating ListBox in Userform with Unique Values on workbook
在通过活动按钮填充工作簿后,我试图用 P 列中的唯一值填充列表框。我已经编写了以下语法,但出于某种原因,它只用第一个单元格数据填充列表框,但停在那里……有什么想法吗?我确定它是我缺少的简单东西,因为我是 VBA.
的新手
Dim Cellrng As Range
Dim Unique As New Collection
Dim Item As Range
On Error Resume Next
For Each Cellrng In ThisWorkbook.Worksheets("START").Range("P8:P" & lRow)
Unique.Add Cellrng, CStr(Cell)
Next Cellrng
On Error GoTo 0
For Each Item In Unique
ListBox1.AddItem Item
Next Item
只需要将 (cell) 更改为 (Cellrng)
Dim Cellrng As Range
Dim Unique As New Collection
Dim Item As Range
Dim lRow As Integer
lRow = wkb.Sheets(1).Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).row
On Error Resume Next
For Each Cellrng In ThisWorkbook.Worksheets("START").Range("P8:P" & lRow)
Unique.Add Cellrng, CStr(Cellrng)
Next Cellrng
On Error GoTo 0
For Each Item In Unique
ListBox1.AddItem Item
Next Item
在通过活动按钮填充工作簿后,我试图用 P 列中的唯一值填充列表框。我已经编写了以下语法,但出于某种原因,它只用第一个单元格数据填充列表框,但停在那里……有什么想法吗?我确定它是我缺少的简单东西,因为我是 VBA.
的新手Dim Cellrng As Range
Dim Unique As New Collection
Dim Item As Range
On Error Resume Next
For Each Cellrng In ThisWorkbook.Worksheets("START").Range("P8:P" & lRow)
Unique.Add Cellrng, CStr(Cell)
Next Cellrng
On Error GoTo 0
For Each Item In Unique
ListBox1.AddItem Item
Next Item
只需要将 (cell) 更改为 (Cellrng)
Dim Cellrng As Range
Dim Unique As New Collection
Dim Item As Range
Dim lRow As Integer
lRow = wkb.Sheets(1).Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).row
On Error Resume Next
For Each Cellrng In ThisWorkbook.Worksheets("START").Range("P8:P" & lRow)
Unique.Add Cellrng, CStr(Cellrng)
Next Cellrng
On Error GoTo 0
For Each Item In Unique
ListBox1.AddItem Item
Next Item