I'm trying to open a workbook FName
from a folder and copy a range from it and paste into a new workbook WBNew
, but i keep getting error
Subscript out of range or 1004 - Application defined
error.
Any idea why ?
Sub NewNumbers()
Dim FName As Workbook, WBNew As Workbook
Set FName = Workbooks.Open(Range("C3") & "\" & Range("C2"))
Set WBNew = Workbooks.Add
FName.Worksheets("Numbers").Range("U2", Range("U2").End(xlToRight)).Copy
WBNew.Sheets("Sheet1").Paste
End Sub
Copy >> Paste is a 1-line Command, also define a Range
in "Sheet1"
to paste.
Dim NumbersSht As Worksheet
' set the copied sheet object
Set NumbersSht = FName.Worksheets("Numbers")
With NumbersSht
.Range("U2", .Range("U2").End(xlToRight)).Copy Destination:=WBNew.Sheets("Sheet1").Range("A1") '<--- Modify "A1" to your desired range
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.