在我的宏中,我有以下代码:
Set v = Application.WorksheetFunction.Index(Worksheets("Sheet2").Range(Cells(2, 1), Cells(33, 3)), Application.WorksheetFunction.Match(1, (Worksheets("Sheet2").Range(Cells(2, 1), Cells(33, 1)) = Osheet.Cells(i, 2).Value) * (Worksheets("Sheet2").Range(Cells(2, 2), Cells(33, 2)) = Left(Osheet.Cells(5, 6).Value, 1)), 0), 3)
数据最初在Sheet 1中(这是代码中使用的Osheet),其中选择了2个参数&索引匹配功能用于从表2中获取数据。
在运行宏时,正在显示运行时错误1004,应用程序定义或对象定义错误。
任何帮助都将受到高度赞赏。
答案 0 :(得分:1)
快速猜测:
with Worksheets("Sheet2")
Set v = Application.WorksheetFunction.Index(.Range(.Cells(2, 1), .Cells(33, 3)), Application.WorksheetFunction.Match(1, (.Range(.Cells(2, 1), .Cells(33, 1)) = Osheet.Cells(i, 2).Value) * (.Range(.Cells(2, 2), .Cells(33, 2)) = Left(Osheet.Cells(5, 6).Value, 1)), 0), 3)
end with
诀窍是你应该将电子表格的引用提供给单元格/范围。只是一个VBA的事情! :)
有关详细信息,请参阅Msdn https://msdn.microsoft.com/en-us/library/office/ff196273.aspx