Moonbeam111
Board Regular
- Joined
- Sep 24, 2018
- Messages
- 73
- Office Version
- 365
- 2010
Hi all. Long time lurker here. Usually I can get my excel question answered by searching the forums but I'm having a bit of a problem with this one, despite its simplicity.
I have two workbooks open, I want to transfer what is in cell H9:H50 in my first open workbook to H9:H50 in the second workbook (preferably pasting only values).
I have this code in Visual Basic, which I found somewhere on these forums, but modified the names and cells to my needs.
But everytime I try to run the macro I get Error: 57121, Application defined or object defined error. When I click debug it highlights this line in yellow --> wb2.Sheets("Sheet1").Range("H9:H150").PasteSpecial.
Now, I don't know if this has a problem to do with Excel or the VB code. Any help here.
I have two workbooks open, I want to transfer what is in cell H9:H50 in my first open workbook to H9:H50 in the second workbook (preferably pasting only values).
I have this code in Visual Basic, which I found somewhere on these forums, but modified the names and cells to my needs.
Code:
Sub Button2_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ActiveWorkbook
'Copy what you want from workbook 1.
wb1.Worksheets("Test").Range("H9:H50").Copy 'Change worksheet
'Open workbook 2
Set wb2 = Workbooks.Open("C:\Users\Matt\Desktop\Excel Folder\Excel Workbook 2.xlsm")
'Paste to worksheet in workbook2:
Application.DisplayAlerts = False
wb2.Sheets("Sheet1").Range("H9:H50").PasteSpecial
Application.CutCopyMode = False
Range("A1").Select
'Close workbook
wb2.Close savechanges:=True
Application.DisplayAlerts = True
End Sub
Now, I don't know if this has a problem to do with Excel or the VB code. Any help here.