允许列表框时ListBox.RowSource不返回任何结果显示没有结果
问题描述:
我目前正在填充列表框的形式用下面的代码:允许列表框时ListBox.RowSource不返回任何结果显示没有结果
'Populate In-Form Table
With ListBox_InFormTable
.ColumnCount = 4
.ColumnWidths = "100;100;100;50"
.RowSource = ws.Range("MasterDataTable").SpecialCells(xlCellTypeVisible).Address
End With
不过,我也积极过滤什么的显示在与窗体中的其他字段的列表框。除了当我滤除所有结果时,这工作正常。而不是得到一个错误,指出:“没有找到细胞。”我宁愿将表格留空。
任何帮助将不胜感激,我一直对我的头撞这一段时间了。
谢谢!
答
你可以尝试这样的事情......
Dim n As Long
With ListBox_InFormTable
.ColumnCount = 4
.ColumnWidths = "100;100;100;50"
On Error Resume Next
n = ws.Range("MasterDataTable").SpecialCells(xlCellTypeVisible).Rows.Count
On Error GoTo 0
If n > 0 Then
.RowSource = ws.Range("MasterDataTable").SpecialCells(xlCellTypeVisible).Address
End If
End With
如果您正在筛选的Excel表,你可以算下过滤的行...
Dim n As Long
With ListBox_InFormTable
.ColumnCount = 4
.ColumnWidths = "100;100;100;50"
On Error Resume Next
n = ActiveSheet.ListObjects("MasterDataTable").Range.Resize(, 1).SpecialCells(xlCellTypeVisible).Count
On Error GoTo 0
If n > 0 Then
.RowSource = ws.Range("MasterDataTable").SpecialCells(xlCellTypeVisible).Address
End If
End With
End Sub
这似乎是工作,但是我用来过滤内置列表框的代码现在看起来并不一致。 以下是代码: 'ActiveSheet.ListObjects(“MasterDataTable”)。Range _ .AutoFilter Field:= 1,Criteria1:=“= *”&TextBox_Employee.Value&“*”' – Syphyx
添加了另一段代码,请参阅如果现在适合你。 – sktneer
不幸的是,现在我再次遇到错误。 :( – Syphyx