VBA used to copy DATA to unopened Workbook

Ragarm13

New Member
Joined
Mar 25, 2018
Messages
19
I have VBA code that copies data from one WB to another, but for some reason the .PasteSpecial xl:= PasteValues doesn't work. I paste the formulas and all.
VBA Code:
Sub trial()

    Dim wb As Workbook
    Dim sheet As Worksheet
    Set sheet = ThisWorkbook.Sheets("FLEX")
    sheet.Activate
    ThisWorkbook.Worksheets("FLEX").Range("B5:K20").Select
    Selection.Copy
    
    Set wb = Workbooks.Open("C:\NewBook.xlsx")
    wb.Worksheets("Time").Activate
    
    lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    ActiveSheet.Cells(lastRow + 1, 1).Select
    
    ActiveSheet.PasteSpecial xl = PasteValues
    ActiveWorkbook.Save
    
    'ActiveWorkbook.Close savechanges = True
    
    Set wb = Nothing
    
    ThisWorkbook.Worksheets("FLEX").Activate
    'ThisWorkbook.Worksheets("FLEX").Cells ("Time")
    
    Application.CutCopyMode = False
    

End Sub

I tried
VBA Code:
ActiveSheet.PasteSpecial xl = PasteValues Paste:=PasteValues
But that didn't work either
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe...

VBA Code:
Sub trial()

    Dim wb As Workbook
    Dim mysheet As Worksheet, DestWS As Worksheet
    Dim lastRow As Long
  
    Set wb = Workbooks.Open("C:\NewBook.xlsx")
  
    Set mysheet = ThisWorkbook.Sheets("FLEX")
    Set DestWS = wb.Worksheets("Time")
  
    lastRow = DestWS.Cells(Rows.Count, 1).End(xlUp).Row
  
    With mysheet.Range("B5:K20")
        DestWS.Cells(lastRow + 1, 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
  
    wb.Save
  

    Set wb = Nothing
  
    ThisWorkbook.Worksheets("FLEX").Activate
 
End Sub

Btw
VBA Code:
 .PasteSpecial xl:= PasteValues
should be
VBA Code:
.PasteSpecial Paste:=xlPasteValues
or just
VBA Code:
.PasteSpecial xlValues
 
Last edited:
Upvote 0
Solution
Maybe...

VBA Code:
Sub trial()

    Dim wb As Workbook
    Dim mysheet As Worksheet, DestWS As Worksheet
    Dim lastRow As Long
 
    Set wb = Workbooks.Open("C:\NewBook.xlsx")
 
    Set mysheet = ThisWorkbook.Sheets("FLEX")
    Set DestWS = wb.Worksheets("Time")
 
    lastRow = DestWS.Cells(Rows.Count, 1).End(xlUp).Row
 
    With mysheet.Range("B5:K20")
        DestWS.Cells(lastRow + 1, 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
    wb.Save
 

    Set wb = Nothing
 
    ThisWorkbook.Worksheets("FLEX").Activate
 
End Sub

Btw
VBA Code:
 .PasteSpecial xl:= PasteValues
should be
VBA Code:
.PasteSpecial Paste:=xlPasteValues
or just
VBA Code:
.PasteSpecial xlValues
That works! Thank you for the info!
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top