vba 如何在具有“findstring”的特定列中的 listobject 表中找到单元格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45790026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 13:08:11  来源:igfitidea点击:

How do I find the cell in a listobject table in a specific column that has "findstring" in it?

excel-vbavbaexcel

提问by rtemen

I am using Excel 2013. I have a listobject excel table called Assembly I need to find the cell that contains "asmb1" in column "Item Name"

我正在使用 Excel 2013。我有一个名为 Assembly 的 listobject excel 表我需要在“项目名称”列中找到包含“asmb1”的单元格

Here is what I have that does work:

这是我所拥有的,确实有效:

Dim ItemRows As Integer
Set AssemblyTable = Worksheets("Assembly").ListObjects("Assembly")
ItemRows = AssemblyTable.ListColumns("Item Name").DataBodyRange.Rows.Count

Here ItemRows gets the proper number of rows in the table.

这里 ItemRows 获取表中正确的行数。

Now I try to do the search and it fails:

现在我尝试进行搜索,但失败了:

Dim ItemRows As Integer
Set AssemblyTable = Worksheets("Assembly").ListObjects("Assembly")
ItemRows = AssemblyTable.ListColumns("Item Name").DataBodyRange.Find("asmb1")

This fails with the following message:

这失败并显示以下消息:

Run-time error '91': Object variable or With block variable not set

Thanks for any ideas. Rich

感谢您的任何想法。富有的

回答by AFBurbano

ItemRowshas to be defined like a Range, after you set ItemRowsto get the result of Find, like that:

ItemRowsRange在设置ItemRows获取 Find 的结果后,必须像 a 一样定义,如下所示:

Dim ItemRows as Range
Set ItemRows = AssemblyTable.ListColumns("Item Name").DataBodyRange.Find("asmb1")