Excel VBA将组合框列表从静态范围更改为动态范围

问题描述 投票:1回答:2

这应该很简单,但我很挣扎。现在,这段代码有效:

cboCategoryEdit1.List = Sheets(2).Range("A2:A40").Value

我试图通过改变组合框的填充方式来“清理”我的项目。我希望它是一个组合框,其范围只需要填充细胞。意思是我需要使用最后一行功能。我将代码更改为此,我只是收到“未找到方法或数据成员”的错误。这是我的问题代码:

Dim i As Range
With Sheets("xRef-Categories")
    Set i = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
Me.cboCategoryEdit1.ListFillRange = i.Address

感谢您对此提供任何帮助。

顺便说一句:Sheet2是“xref-Categories”

excel vba excel-vba combobox
2个回答
0
投票

你只需要这个......

With Sheets("xRef-Categories")
    Me.cboCategoryEdit1.List = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With

0
投票

您可以像这样简化它:

With Sheets("xRef-Categories")
    Me.cboCategoryEdit1.List = .Range("A2" , .Range("A" & .Rows.Count).End(xlUp)).Value
End With
© www.soinside.com 2019 - 2024. All rights reserved.