2017-02-07 171 views
1

我有下面的代碼運行良好。我不知道是什麼改變了,突然我得到錯誤「對象變量或帶塊變量未設置」排隊對象變量或With塊變量未設置錯誤在vba

Range(Test(0)) = wf.CountIfs(.Rows(1).Find(Test(2), lookat:=xlWhole).EntireColumn, Test(3))

我的代碼:

Sub WBR() 

Dim Count1Criteria As Variant 
Dim Count3Criteria As Variant 
Dim Test As Variant 
Dim wf As WorksheetFunction 
Set wf = Application.WorksheetFunction 



Filter1InSummary = Array(Array("AH4", "Latency", "Pass/Fail", "Pass"), _ 
         Array("AH5", "Latency", "Pass/Fail", "Fail"), _ 
         Array("AH44", "TT", "Able to repro", "Not Tested"), _ 
         Array("AH47", "TT", "Reason for Reasssignment/Resolving", "Duplicate TT"), _ 
         Array("AH51", "TT", "Able to repro", "Yes"), _ 
         Array("AH52", "TT", "Able to repro", "No"), _ 
         Array("AH61", "Reactive", "Item Type", "Item"), _ 
         Array("AH46", "TT", "Reason for Reasssignment/Resolving", "Hardware Unavailable"), _ 
         Array("AH41", "TT", "Severity", "2"), _ 
         Array("AH62", "Reactive", "Trigger Key Name", "*App Crashes*"), _ 
         Array("AH63", "Reactive", "Trigger Key Name", "*Download*"), _ 
         Array("AH49", "TT", "Reason for Reasssignment/Resolving", "Insufficient Information"), _ 
         Array("AH15", "Latency", "Comments", "*Waived since unable to repro issue*"), _ 
         Array("AH6", "Latency", "Comments", "*Waived since unable to repro issue*"), _ 
         Array("AH16", "Latency", "Comments", "*Waived due to business reasons*"), _ 
         Array("AH18", "Non-Mhowls", "Type of testing", "Full Testing"), _ 
         Array("AH19", "Non-Mhowls", "Type of testing", "Upgrade Testing"), _ 
         Array("AH21", "DRG", "Failure testing type", "Normal Testing"), _ 
         Array("AH22", "DRG", "Failure testing type", "Deep Testing")) 




For Each Test In Filter1InSummary 
    With Worksheets(Test(1)) 
     Range(Test(0)) = wf.CountIfs(.Rows(1).Find(Test(2), lookat:=xlWhole).EntireColumn, Test(3)) 
    End With 
Next 
+0

想必它沒有找到價值?你只是指定了一個可能沒有幫助的參數。 – SJR

+0

一個參數?你可以在外行期間解釋嗎?我需要提供哪些信息來找出這裏出現的問題? –

+0

通過您的代碼來檢查發生了什麼。如果您認爲某個值存在但您沒有找到它,則可能是由於某個Find的參數。看看VBA的幫助或例如https://msdn.microsoft.com/en-us/library/office/ff839746.aspx(順便說一句,我認爲你只需要CountIf。) – SJR

回答

0

我修正了錯誤。其中一列沒有出現在我正在測試的測試數據中!

一旦我找出丟失的數據並添加它,問題得到修復!

1

你忘了全使用Worksheet(Test(1))來減少您的Range(Test(0))

改變您的線路:

Range(Test(0)) = wf.CountIfs(.Rows(1).Find(Test(2), lookat:=xlWhole).EntireColumn, Test(3))

到:

.Range(Test(0)).Value = wf.CountIfs(.Rows(1).Find(Test(2), lookat:=xlWhole).EntireColumn, Test(3))

注意:我已經添加了Value爲良好的編碼實踐的研究,這是沒有必要

+0

以下感謝@Shai Rado的建議。但即使添加建議的行後,我也會得到相同的錯誤代碼......如果指定的任何Col/Worksheet不存在,是否會發生此錯誤? –

相關問題