【发布时间】:2019-03-20 12:58:38
【问题描述】:
我正在尝试在 for 循环中设置数组公式,以将字符串与另一个名为 Project Name 的工作表上的名称列表进行部分匹配。这应该是end product 我使用exceljet 中的方法在电子表格中得到了公式,但是当我尝试将其转换为VBA 时遇到了“需要对象”的错误。 cells(i,6) 是我试图与项目名称进行部分匹配的字符串的位置。该列不必是“6”,它是请帮助的地方。谢谢!
Sub Shortname()
Dim SRng As Variant
Dim SName As Integer
Dim SNrow As Integer
Dim PLcol As Integer
Dim PLrow As Integer
Worksheets(3).Activate
SNrow = Cells(Rows.Count, 1).End(xlUp).Row
SRng = Range(Cells(2, 1), Cells(SNrow, 1)).Value
Worksheets(2).Activate
PLcol = Cells(1, Columns.Count).End(xlToLeft).Column + 1
PLrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To PLrow
Cells(i, PLcol).Value = Application.WorksheetFunction.Index(SRng, Application.WorksheetFunction.Match("TRUE", Application.WorksheetFunction.IsNumber(Application.WorksheetFunction.Search(SRng.Value, Cells(i, 6))), 0), 1)
Next i
End Sub
【问题讨论】:
-
请阅读stackoverflow.com/questions/10714251/…,因为您的代码按照现在的编写方式容易出错,无需明确引用工作表/书籍
标签: vba indexing match array-formulas