使用现有的命名范围定义范围&偏移/调整

时间:2017-02-01 19:18:38

标签: vba excel-vba excel

我正在尝试使用现有的命名范围来引用不同的行(列应该相同)。现在我有以下内容:

Dim DetailONE, DetailONW, DetailW, DetailQc As Range
Set DetailONE = Sheet11.Range("CM12:EG13")
Set DetailONW = Sheet11.Range("EI12:GC13")
Set DetailW = Sheet11.Range("GE12:HO13")
Set DetailQc = Sheet11.Range("HQ12:IT13")

然后我引用那些命名范围,但我得到一个应用程序定义或对象定义错误,如下所示。有谁知道为什么?我不知道之后是否需要.Address部分,或者如果我可以放弃它。

Dim OntarioWestDet, OntarioEastDet, WestDet, QuebecDet As Range
Set OntarioWestDet = Sheet11.Range(DetailONW.Address).Offset(3, 0).Resize(300, 0)
Set OntarioEastDet = Sheet11.Range(DetailONE).Offset(3, 0).Resize(300, 0)
Set WestDet = Sheet11.Range(DetailWe).Offset(3, 0).Resize(300, 0)
Set QuebecDet = Sheet11.Range(DetailQc).Offset(3, 0).Resize(300, 0)

1 个答案:

答案 0 :(得分:1)

这对我有用(你的一个名字中有一个拼写错误

Sub x()

Dim DetailONE As Range, DetailONW As Range, DetailW As Range, DetailQc As Range
Set DetailONE = Sheet11.Range("CM12:EG13")
Set DetailONW = Sheet11.Range("EI12:GC13")
Set DetailW = Sheet11.Range("GE12:HO13")
Set DetailQc = Sheet11.Range("HQ12:IT13")

Dim OntarioWestDet As Range, OntarioEastDet As Range, WestDet As Range, QuebecDet As Range
Set OntarioWestDet = DetailONW.Offset(3, 0).Resize(300)
Set OntarioEastDet = DetailONE.Offset(3, 0).Resize(300)
Set WestDet = DetailW.Offset(3, 0).Resize(300)
Set QuebecDet = DetailQc.Offset(3, 0).Resize(300)

End Sub