Reputation: 171
I'm running this code to copy data from one workbook into another main workbook but keep getting runtime error 438 at line 12. Whats going on? Thanks in advance!
1 Sub copydata()
2 Dim wbk As Workbook
3 Dim wbk2 As Workbook
4 strFirstFile = Userform1.path.Text
5 Set wbk2 = ThisWorkbook
6 Set wbk = Workbooks.Open(strFirstFile)
7 With wbk.Sheets(1)
8 Cells(1, 1).Activate
9 ActiveCell.CurrentRegion.Select
10 Selection.Copy
11 End With
12 wbk2.Sheets("UAL").Range("G1").Paste
13 Application.CutCopyMode = False
14 wbk.Close
15
16 End Sub
Upvotes: 2
Views: 1147
Reputation: 35853
Range
doesn't support method Paste
. Use this pattern:
Selection.Copy Destination:=wbk2.Sheets("UAL").Range("G1")
or you can use PasteSpecial
:
wbk2.Sheets("UAL").Range("G1").PasteSpecial xlPasteAll
BTW, avoid using Select
statement. You can use this one instead lines 7-12 (which are not correct in your code, since you've missed period .
before Cells(1, 1)
and etc):
With wbk.Sheets(1)
.Cells(1, 1).CurrentRegion.Copy Destination:=wbk2.Sheets("UAL").Range("G1")
End With
Upvotes: 1