0

我已经搜索了大约一个小时,但没有发现任何可以解决我的问题。以下代码

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被声明为字符串或变体来引用范围都没有关系。

例如,字符串q3j1Name等初始化良好。工作得很好。q3j1Name"Q3_2012"Set q3Uebj1 = Range("Q3_2013")

命名范围存在,但在不同的工作表中。Set q3Uebj1 = Worksheets(2).Range(q3j1Name)也不行。

有没有人建议我如何解决这个问题或解决它?

基本上,正在逐步执行的每个工作表都包含一个年份值,基于该值使用 worksheet2 中的范围。

在此先感谢您的帮助...

4

1 回答 1

0

尝试这个:

Set q3Uebj1 = Thisworkbook.Sheets(2).Range(q3j1Name)

此外,请确保您正确引用了图纸编号。

于 2013-11-06T08:39:39.210 回答