![](/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.