2017-02-07 132 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不存在,是否会发生此错误? –

相关问题