You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整Excel用户窗体ListBox的垂直滚动条范围

解决ListBox滚动条行数适配问题

你的问题根源在代码逻辑错误:每找到一行符合筛选条件的数据时,你在k的循环里重复执行了.AddItem,导致一行有效数据被添加了6次(因为k从3到8共6次循环),ListBox实际行数是有效数据的6倍,这才让滚动条误以为有几百行,底部出现空白。

修正方法很简单,把.AddItem移到k循环外面,每一行有效数据只新增1行,再给这一行的6列依次赋值:

Sub RefreshLBIndoor()
    Dim i As Integer, j As Integer, k As Byte
    With ListBoxIndoor ' This is the listbox name
        .Clear ' 先清空原有内容,避免重复加载
        .ColumnCount = 6
        j = 1
        For i = 3 To SupportList.ListObjects("ProductList_table").DataBodyRange.Rows.Count + 2 ' Data begins from row 3
            ' Column F (number 6) contains the filter for which rows to populate the listbox
            If InStr(1, SupportList.Cells(i, 6), "Example", vbTextCompare) = 1 Then 
                .AddItem ' 只新增一行
                For k = 3 To 8
                    .Column(k - 3, j - 1) = SupportList.Cells(i, k).Value
                Next k
                j = j + 1
            End If
        Next i
        On Error Resume Next
        .ListIndex = 0
    End With
End Sub

额外建议:添加.Clear方法清空ListBox原有内容,避免多次执行代码时数据重复累加,进一步保证行数准确。

内容的提问来源于stack exchange,提问作者João Ramos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 23:42:02