我已经搜索了大约一个小时,但没有发现能解决我的问题。以下代码
Dim q3ZFj1 As Range
Dim q4ZFj1 As Range
Dim q3ZFj2 As Range
Dim q4ZFj2 As Range
Dim q3Uebj1 As Range
Dim q4Uebj1 As Range
Dim q3Uebj2 As Range
Dim q4Uebj2 As Range
Dim cRow As Long
Dim cCol As Long
Dim startYear As Integer
Dim nextYear As Integer
Dim q3j1Name As Variant
Dim q4j1Name As String
Dim q3j2Name As String
Dim q4j2Name As String
Dim c As Variant
For i = 3 + 1 To Sheets.Count
Set q3ZFj1 = Worksheets(i).Range("C501:I512")
Set q4ZFj1 = Worksheets(i).Range("C521:I532")
Set q3ZFj2 = Worksheets(i).Range("C601:I612")
Set q4ZFj2 = Worksheets(i).Range("C621:I632")
startYear = q3ZFj1.Cells(-1, 0)
nextYear = startYear + 1
q3j1Name = "Q3_" & startYear
q4j1Name = "Q4_" & startYear
q3j2Name = "Q3_" & nextYear
q4j2Name = "Q4_" & nextYear
Set q3Uebj1 = Range(q3j1Name)
Set q4Uebj1 = Range("Q4_" & startYear)
Set q3Uebj2 = Range("Q3_" & nextYear)
Set q4Uebj2 = Range("Q4_" & nextYear)
使用F8单步执行时运行正常,但运行时,我会收到标题中提到的错误。
使用Range(q3j1Name)
或Range("Q3_" & startYear)
引用范围或q3j1Name
的变量是否声明为String或Variant无关紧要。
字符串q3j1Name
等初始化为好,q3j1Name
为"Q3_2012"
。 Set q3Uebj1 = Range("Q3_2013")
工作得很好。
命名范围存在,但在不同的工作表中。 Set q3Uebj1 = Worksheets(2).Range(q3j1Name)
也不起作用。
是否有人建议我如何修复此问题或解决此问题?
基本上,逐步执行的每个工作表都包含一个年份值,根据该值使用工作表2中的范围。
提前感谢您的帮助......
答案 0 :(得分:0)
试试这个:
Set q3Uebj1 = Thisworkbook.Sheets(2).Range(q3j1Name)
另外,请确保正确引用纸张编号。