2017-02-28 45 views
0

我正嘗試使用VBA來定義一個變量,以便在不同的工作表上的單個列中發生的事件數量。我試圖計算「承保」列出現在列S中的次數。Countif不在工作表中工作

我得到運行時錯誤'438' - 對象不支持此屬性或方法。

誰能告訴我我做錯了什麼?

錯誤指向我與「piperow開頭的行= ...

Sub Resize_Template() 

Dim pipeRow As Long 

pipeRow = ActiveWorkbook.Sheets("Pipeline - Underwriting Data D").countif(Range("S:S"), "Underwriting") 

End Sub 

感謝您的幫助!

+0

'CountIf'是不是'Worksheet'的方法 - 它是'Application.WorksheetFunction'函數。 – YowE3K

回答

1

您需要使用Application.WorksheetFunction.

pipeRow = Application.WorksheetFunction.Countif(ActiveWorkbook.Sheets("Pipeline - Underwriting Data D").Range("S:S"), "Underwriting") 
+0

非常棒!非常感謝。 – AdMac