Search code examples
excelvbacopy-paste

Pasting a range of values from one workbook to another


So everything was actually pasting correctly to the workbook, however, I added an extra column of data that has a formula entered in it. Now when I run the macro it is copying and pasting the formula rather than the value generated from the formula.

I went in and changed wbData.ActiveSheet.Paste to wbData.ActiveSheet.PasteSpecial x1PasteValue but it is not working. Wondering if I inserted it into the wrong location?

 Dim wbTime As Workbook
   Set wbTime = ThisWorkbook
   Dim wbData As Workbook
   Dim LastRow As Long

   Set wbTime = ActiveWorkbook
   With wbTime.Sheets("Production Time Sheet")
       LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
   End With
   wbTime.Sheets("Production Time Sheet").Range("A6:O" & LastRow).Copy

   Set wbData = Workbooks.Open("S:\Lean Carrollton Initiative\Michael\Time Sheet Data - LT Test.xlsx")

   wbData.ActiveSheet.PasteSpecial x1PasteValue Destination:=Worksheets("Log").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)

   wbData.Close SaveChanges:=True
End Sub

Solution

  • I would always select the range to paste too first

    Worksheets("Log").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValue