我有一个从工作表中填充的列表框。我正在使用外观来阅读每一行并更新列表框,但我的标题显示为空白

问题描述 投票:0回答:0

大家好,这是我的代码,它从我的供应商表选项卡中提取信息,但我的 .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 循环)

excel vba listbox columnheader
© www.soinside.com 2019 - 2024. All rights reserved.