简体   繁体   English

Excel VBA-无法找到导致“运行时错误91”的错误

[英]Excel VBA - Unable to find error causing 'runtime error 91'

I have the below code which is causing a 我有以下代码,这导致

runtime error 91 - Object Variable not set 运行时错误91-未设置对象变量

I have dim'd each workbook, worksheet, and variable, but it does not remove the error. 我已将每个工作簿,工作表和变量调暗,但不能消除错误。

    Dim r As Long, c As Long
    Dim snowq As Workbook, CAQual As Workbook, qsum As Worksheet, CAqsum As Worksheet
    For r = 2 To 8
        For c = 2 To 4
            combinedReports.Worksheets("combinedQualities").Cells(r, c).Value = _
                snowq.Worksheets("qsum").Cells(r, c).Value + CAQual.Worksheets("CAqsum").Cells(r, c).Value
        Next
    Next

NOTE that the first workbook and worksheet are dim'd further up in the code but within the same module. 注意,第一个工作簿和工作表在代码的更深处但在同一模块中。

Any assistance is appreciated. 任何帮助表示赞赏。

EDIT: 编辑:

This is the top of the module which includes setting the actual workbook and worksheet(s): 这是模块的顶部,其中包括设置实际的工作簿和工作表:

'Create new workbook
Dim combinedReports As Workbook, combinedCsats As Worksheet, combinedQualities As Worksheet, combinedTickets As Worksheet
Set combinedReports = Workbooks.Add
Sheets("Sheet1").name = "Combined CSAT's"
Set combinedCsats = combinedReports.Sheets("Combined CSAT's")
Sheets.Add After:=ActiveSheet
Sheets("Sheet2").name = "Combined Qualities"
Set combinedQualities = combinedReports.Sheets("Combined Qualities")
Sheets.Add After:=ActiveSheet
Sheets("Sheet3").name = "Combined Tickets"
Set combinedTickets = combinedReports.Sheets("Combined Tickets")

Insert this code before the For r = 2 to 8 loop the code will stop on the faulty object. For r = 2 to 8循环之前插入此代码,该代码将在有故障的对象上停止。

Debug.Print combinedReports.Name
Debug.Print combinedReports.Worksheets("combinedQualities").Name
Debug.Print snowq.Name
Debug.Print snowq.Worksheets("qsum").Name
Debug.Print CAQual.Name
Debug.Print CAQual.Worksheets("CAqsum").Name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM