Search code examples
excelvbacopycopy-pastepaste

VBA Copy Paste without formatting from another workbook


I have this code which helps me to copy paste information from one workbook to another. The values get pasted with format and formulas, but I want to paste them as simple text. I have tried to add the .PasteSpecial Paste:=xlPasteValues but I get an error saying Compile Error: Expected: end of statement.

Sub get_data()
 
Dim Wb1 As Workbook
 
'Dont update screen, works faster.
Application.ScreenUpdating = False
 
'Open Workbook. Input FULL path inside quotation marks, including extension of the file.
Set Wb1 = Workbooks.Open("wocnewoi.xlsm")
 
'Data gets filled with the following code:
 
'Information
Wb1.Worksheets("Info").Range("G14").Copy _
    ThisWorkbook.Worksheets("Information").Range("C6")
    
Wb1.Worksheets("Info").Range("G16").Copy _
    ThisWorkbook.Worksheets("Information").Range("C8")

Wb1.Close SaveChanges:=False
    
Application.ScreenUpdating = True

End Sub

Solution

  • Assigning a value directly to a cell is more efficient than using Copy/PasteSpecial.

    Please try.

        ThisWorkbook.Worksheets("Information").Range("C6").Value = _
            Wb1.Worksheets("Info").Range("G14").Value
        ThisWorkbook.Worksheets("Information").Range("C8").Value = _
            Wb1.Worksheets("Info").Range("G16").Value