Countifs语句编译,但由于运行时错误438失败



我有一个宏,该宏可以从同一本书中的另一张纸中的数据上构建图表。目前,它编译但停止了countifs语句,该语句查看其他纸上的日期。

有问题的线是:

thisBook.rSheet.Range(i, "T") = Application.WorksheetFunction.CountIfs( _
thisBook.sSheet.Cells("K2", "K" & sSheet.Cells(Rows.Count, "K").End(xlUp).Row), "APPROVED", _
thisBook.sSheet.Cells("M2", "M" & sSheet.Cells(Rows.Count, "M").End(xlUp).Row), ">=" & (rSheet.Range(i, "S").Value2 - 6), _
thisBook.sSheet.Cells("M2", "M" & sSheet.Cells(Rows.Count, "M").End(xlUp).Row), "<=" & (rSheet.Range(i, "S").Value2))

该语句旨在在另一个表上计算行,其中k列中的文本等于"已批准",并且在特定一周内在列中有一个日期。我循环穿过这张桌子的8行。S列是一周结束的日期。

一切都被完全引用避免

运行时错误1004

本书是工作簿,rsheet是带有图表的工作簿,Ssheet是带有表的表格。

哪个对象不支持此处的属性或方法?

尝试一下,稍微调整以使其更容易阅读/关注:

Dim outputRng As Range
Dim rSheetVal as Date 
Set outputRng = rsheet.Range(i, "T")
rSheetVal = rsheet.Cells(i, "S").Value2   ' OR, rsheet.Range("S"&i).Value2
With thisBook.sSheet
    outputRng = Application.WorksheetFunction.CountIfs( _
                .Range("K2", "K" & .Cells(Rows.Count, "K").End(xlUp).Row), "APPROVED", _
                .Range("M2", "M" & .Cells(Rows.Count, "M").End(xlUp).Row), ">=" & (rSheetVal-6), _
                .Range("M2", "M" & .Cells(Rows.Count, "M").End(xlUp).Row), "<=" & (rSheetVal))
End With

假设thisBookrsheet设置为:

Set thisBook = ActiveWorkbook
Set rSheet = thisBook.Sheets("r Sheet")

相关内容

最新更新