0
votes

Basically I want to create a new workbook and copy some data from an already-opened workbook (Filename) and paste it into the new workbook. I have the following vba code:

Workbooks.Add
Set new_wb = ActiveWorkbook
Workbooks(Filename).Worksheets("pivot").Range("A28").Activate
ActiveCell.CurrentRegion.Select
Selection.Copy Destination:=new_wb.Worksheets("Sheet1").Range("B2")

However, I do not see anything pasted into the new workbook. Thus, I was wondering if I was doing anything wrong. Any insight would be greatly appreciated. Thanks!

1

1 Answers

0
votes

Avoid using Select and Activate:

Workbooks.Add
Set new_wb = ActiveWorkbook
Workbooks(Filename).Worksheets("pivot").Range("A28").CurrentRegion.Copy Destination:=new_wb.Worksheets("Sheet1").Range("B2")