Results 1 to 10 of 86

Thread: Copy Paste based on comparisons calculations in 2 XL files, 1 might be .csv file .Opened in XL=Fail/Chaos

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Hi,


    To copy all columns is not usually good to do. In whole columns you maybe do not heed all rows

    But this is what you asked for

    vba is placed in a separate file sample1.xlsm
    File is attached : FileAttatchedToPost.jpg : https://imgur.com/xFLyqLQ

    copy all the data from column A TO COLUMN H complete data from sample2.xls
    Columns("A:H").Copy


    paste it to sample3.xlsb in same columns
    I recommend using the Range PasteSpecial Method
    http://eileenslounge.com/viewtopic.p...=34112#p264458
    http://www.eileenslounge.com/viewtop...=25002#p193871
    https://docs.microsoft.com/en-us/off...e.pastespecial


    You can chose the way you want to Paste, and formats
    https://docs.microsoft.com/en-us/off...el.xlpastetype
    .PasteSpecial Paste:= xlPasteValuesAndNumberFormats
    .PasteSpecial Paste:= xlPasteFormats
    .PasteSpecial Paste:= xlPasteColumnWidths




    save and close the sample2.xls and sample3.xlsb
    You can
    Save
    Or
    Save As

    I did do macro recording to check syntax:
    http://www.excelfox.com/forum/showth...ll=1#post12531

    You can just Save That is enough in your case.
    ( You can also SaveAs )

    Code:
    Sub CopyAllColumns()
    ' copy all the data from column A TO COLUMN H complete data from sample2.xls
     Workbooks("sample2.xls").Worksheets.Item(1).Columns("A:H").Copy '
    ' paste it to sample3.xlsb in same columns
     Workbooks("sample3.xlsb").Worksheets.Item(1).Columns("A:H").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                                                                                                 'Workbooks("sample3.xlsb").Worksheets.Item(1).Range("A1:H65536").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
     Workbooks("sample3.xlsb").Worksheets.Item(1).Columns("A:H").PasteSpecial Paste:=xlPasteFormats
     Workbooks("sample3.xlsb").Worksheets.Item(1).Columns("A:H").PasteSpecial Paste:=xlPasteColumnWidths
     
    ' save and close the sample2.xls and sample3.xlsb   '   http://www.excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)?p=12531&viewfull=1#post12531
     Workbooks("sample2.xls").Save
    ' or
     Workbooks("sample2.xls").SaveAs Filename:=ThisWorkbook.Path & "\sample2.xls", FileFormat:=xlExcel8
    
     Workbooks("sample3.xlsb").Save
    ' or
     Workbooks("sample3.xlsb").SaveAs Filename:=ThisWorkbook.Path & "\sample3.xlsb", FileFormat:=xlExcel12
    
     Workbooks("sample2.xls").Close: Workbooks("sample3.xlsb").Close
    End Sub
    

    Alan
    Attached Files Attached Files
    Last edited by DocAElstein; 03-03-2020 at 02:09 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Replies: 26
    Last Post: 09-26-2020, 05:56 PM
  2. Copy paste data based on criteria
    By analyst in forum Excel Help
    Replies: 7
    Last Post: 01-13-2014, 12:46 PM
  3. Replies: 8
    Last Post: 10-31-2013, 12:38 AM
  4. Replies: 2
    Last Post: 09-18-2013, 12:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •