Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading