+ Reply to Thread
Results 1 to 4 of 4

Cells format change after copy and paste data

Hybrid View

  1. #1
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Cells format change after copy and paste data

    Hi

    I'm going creazy, because when SAP export to excel file, I don't know why, the file is created with the extension XLS

    I need copy data in One tab("cobaia") from file "cobaia.XLS" and paste into file "PasteHere.xlsm"

    When I copy data by VBA, something wrong happening, if you look in columns(T,W,X,Y,Z,AA,AC,AD,AE,AF,AG,AI,AJ,AK,AL,AN,AO,AP), the value came with "error" (spaces, not number)

    I'm using this code below.
    Sub Stole_this_Code_from_davesexcel()
    'http://www.excelforum.com/excel-programming-vba-macros/1063028-copy-related-cells-from-different-workbooks-to-same-workbook.html
    'Sorry I stole this code from davesexcel
        Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
        Dim Rws As Long, Rng As Range
        Set Wb = ThisWorkbook
        'change the address to suite
        MyDir = "C:\Users\monica\Downloads\Monica\"
        MyFile = Dir(MyDir & "cobaia.XLS")    'change file extension
        ChDir MyDir
        Application.ScreenUpdating = 0
        Application.DisplayAlerts = 0
    
        Do While MyFile <> ""
            Workbooks.Open (MyFile)
            With Worksheets("cobaia")
                Rws = .Cells(Rows.Count, "C").End(xlUp).Row
                Set Rng = Range(.Cells(1, 1), .Cells(Rws, 44))
                Rng.Copy Wb.Worksheets("Relatorio").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                ActiveWorkbook.Close True
            End With
            MyFile = Dir()
        Loop
    
    End Sub
    My files size 72Mb, because this, I paste files on GoogleDrive:
    https://drive.google.com/drive/folde...fE?usp=sharing

    Thank you!!
    Last edited by marreco; 05-06-2019 at 03:27 PM.
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Cells format change after copy and paste data

    When you do a full copy and paste, you get everything, formats, formulas, conditional formatting, validations, etc.

    If you want to preserve the formats in the workbook being copied into, change this line:
    Rng.Copy Wb.Worksheets("Relatorio").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    To this:
    Rng.Copy 
    Wb.Worksheets("Relatorio").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).pastespecial xlpastevalues
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Cells format change after copy and paste data

    Hi dflank

    I need test this in my job tomorrow, anyway, before I mark as solved, can you help with more one task?

    Sub Stole_this_Code_from_davesexcel()
    'http://www.excelforum.com/excel-programming-vba-macros/1063028-copy-related-cells-from-different-workbooks-to-same-workbook.html
    'Sorry I stole this code from davesexcel
        Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
        Dim Rws As Long, Rng As Range
        Set Wb = ThisWorkbook
        'change the address to suite
        MyDir = "C:\Users\mareco\Downloads\"
        MyFile = Dir(MyDir & "cobaia.XLS")    'change file extension
        ChDir MyDir
        Application.ScreenUpdating = 0
        Application.DisplayAlerts = 0
    
        Do While MyFile <> ""
            Workbooks.Open (MyFile)
            With Worksheets("cobaia")
                Rws = .Cells(Rows.Count, "C").End(xlUp).Row
                Set Rng = Range(.Cells(1, 1), .Cells(Rws, 44))
                Rng.Copy Wb.Worksheets("Relatorio").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                ActiveWorkbook.Close True
            End With
            MyFile = Dir()
        Loop
        '----- help me with too, please? ------
        With Worksheets("Relatorio")
        'After paste data, I need do little thing...
        'How to remove all blank rows and keep one single header(Nş NF|Data doc.|Dt.lçto.|CN|Cat. Nota Fiscal|Estornado  ...Etc)?
            .Range("A:B").Delete
            .Range("A1:A" & Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
            .Columns.AutoFit
        End With
    End Sub

    Thank you!!

  4. #4
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Cells format change after copy and paste data

    Hi

    I do my test, but it does not work, look at my attachment.
    The numbers is paste not like number (in up left corner of cell, show green simbol).

    Is there fast way todo this?
    Code below solve, but I need some more fast.
    Public Sub Change_to_Number()
    'I have only 2 days of data, this mean 80138 rows
    'Code below salve, but take aa long time.
      Dim rngCelula As Range
      For Each rngCelula In Range("U2:AN80000") 'Selection
        rngCelula.FormulaLocal = rngCelula.Value
      Next rngCelula
    End Sub
    Thank you!!
    Attached Images Attached Images
    Last edited by marreco; 05-08-2019 at 12:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. copy abbreviated format add a , add a cells value and paste to only blank cells
    By kleptilian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-23-2014, 02:26 PM
  2. Replies: 1
    Last Post: 01-16-2013, 05:36 AM
  3. Copy Format and paste to range of cells
    By Longpod in forum Excel General
    Replies: 4
    Last Post: 06-27-2012, 02:22 AM
  4. [SOLVED] Copy data in one format from Sheet1 and paste to another sheet in another format.
    By FergusC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2012, 08:36 PM
  5. Can you change the format of copy/paste?
    By noidea in forum Excel General
    Replies: 3
    Last Post: 08-04-2007, 10:02 PM
  6. copy & paste and change format
    By SLB in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-09-2006, 08:29 AM
  7. Lock Cell Format - Allow copy and paste of data without format change
    By Chris12InKC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2006, 12:50 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1