计算行时,“对象不支持属性或方法”错误

时间:2016-07-20 21:56:32

标签: vba excel-vba excel

以下代码产生Object does not support this property or method错误:

With CellsTab
    NumOfProdCells = .Range(.Cells(.Match(CurrentStartRow,.Range("MIRCellColumn"), 0), 4), 
    .Cells(.Match(CurrentStartRow,.Range("MIRCellColumn"), 0), 4).End(xlDown)).Rows.Count 
End With

CellsTab是一个工作表,NumOfProdCell的类型为long,CurrentStartRow也是一个整数,MIRCellColumn是工作表CellsTab中的命名范围}。

1 个答案:

答案 0 :(得分:3)

由于.match而失败。 .match是一个工作簿函数,但您正在使用它,就像它是工作表的方法一样。而是使用:

With CellsTab
    NumOfProdCells = _
        .Range(.Cells(Application.WorksheetFunction.Match(CurrentStartRow, _
        .Range("MIRCellColumn"), 0), 4), _
        .Cells(Application.WorksheetFunction.Match(CurrentStartRow, _
        .Range("MIRCellColumn"), 0), 4).End(xlDown)).Rows.Count
End With