![](/img/trans.png)
[英]VBA Excel: How to assign range of cells to another range of cells?
[英]How to assign range of cells to Range variable
我的环境:MS Excel 2013
我想用下面的代码将单元格范围分配给我的范围变量
Dim strSourceFile As String
Dim wbSource As Workbook
strSourceFile = "D:\csv1.csv"
Set wbSource = Workbooks.Open(strSourceFile)
Set rngY = wbSource.Sheets(1).Range(Cells(2, RefCol), Cells(LastSource, RefCol))
尝试为rngY
赋值时,最后一行出现错误。
Run-time error '1004':
Application-defined or object-defined error
Cells(2, RefCol)
引用活动工作表上的单元格。 您必须限定所有范围对象。
范例1:
Set rngY = wbSource.Sheets(1).Range( wbSource.Sheets(1).Cells(2, RefCol), wbSource.Sheets(1).Cells(LastSource, RefCol))
范例2:
With wbSource.Sheets(1)
Set rngY = .Range( .Cells(2, RefCol), .Cells(LastSource, RefCol))
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.