大家好,这是我的代码,它从我的供应商表选项卡中提取信息,但我的 .ColumnCount 将我的标题留空......关于为什么的任何想法?
非常感谢!
私人子更新供应商LB() 昏暗 last_row 一样长 将 vsheet 调暗为工作表 昏暗我一样长
Set vsheet = ThisWorkbook.Worksheets("Suppliers")
Me.Suppliers_Listbox.ListIndex = -1 ' Clears the listbox
last_row = vsheet.Cells(vsheet.Rows.Count, "A").End(xlUp).Row
With Suppliers_Listbox
.Clear
.ColumnCount = 6
.ColumnHeads = True
.ColumnWidths = "30,90,90,90,80,120"
For i = 2 To last_row ' i = 2 data starts at row 2 row 1 is for header
If inactive_cb.Value = True Then ' This filters to show only active suppliers
If vsheet.Cells(i, "G").Value = "Y" Then
.AddItem vsheet.Cells(i, "A").Value
.List(.ListCount - 1, 1) = vsheet.Cells(i, "B").Value
.List(.ListCount - 1, 2) = vsheet.Cells(i, "C").Value
.List(.ListCount - 1, 3) = vsheet.Cells(i, "D").Value
.List(.ListCount - 1, 4) = vsheet.Cells(i, "E").Value
.List(.ListCount - 1, 5) = vsheet.Cells(i, "F").Value
End If
Else
.AddItem vsheet.Cells(i, "A").Value
.List(.ListCount - 1, 1) = vsheet.Cells(i, "B").Value
.List(.ListCount - 1, 2) = vsheet.Cells(i, "C").Value
.List(.ListCount - 1, 3) = vsheet.Cells(i, "D").Value
.List(.ListCount - 1, 4) = vsheet.Cells(i, "E").Value
.List(.ListCount - 1, 5) = vsheet.Cells(i, "F").Value
End If
Next i
End With
结束子
更新如果我使用: .RowSource = "Suppliers!A2:F" & last_row - 1 (它与标题完美配合,但我可能不需要每一行,所以我使用了 for 循环)