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
How do I find the cell in a listobject table in a specific column that has "findstring" in it?
提问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
ItemRows
has to be defined like a Range
, after you set ItemRows
to get the result of Find, like that:
ItemRows
Range
在设置ItemRows
获取 Find 的结果后,必须像 a 一样定义,如下所示:
Dim ItemRows as Range
Set ItemRows = AssemblyTable.ListColumns("Item Name").DataBodyRange.Find("asmb1")