+ Reply to Thread
Results 1 to 4 of 4

Paste Special Values losing destination formatting

Hybrid View

  1. #1
    Registered User
    Join Date
    12-22-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    19

    Paste Special Values losing destination formatting

    I have a macro which copies a filtered range and pastes the data into columns in another sheet. I am pasting using the below code:

    Range("A4").Select
    Selection.PasteSpecial Paste:=xlPasteValues
    It works fne however I am losing the formatting in the destination table. e.g. One column has been formatted as DATE (DD/MM/YYYY) but when the macro pastes values it pastes as general and values appears as numbers.
    Just to confirm, I want to keep the formatting in the destination table, not the source.


    Any idea how to resolve this?

    Thanks!
    Last edited by mr_newbie; 03-07-2016 at 06:42 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Paste Special Values losing destination formatting

    That should work.

    Option Explicit
    
    ' basic recorded macro with S1.B3 and S2.A4 pre-selected
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
    Selection.Copy
    Sheets("Sheet2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("A:A").EntireColumn.AutoFit
    End Sub
    
    ' adapted macro to avoid selection
    Sub sCopyPasteSpecial()
    
    Sheets("Sheet1").Range("B4").Copy
    With Sheets("Sheet2")
        With .Range("A4")
            .PasteSpecial _
                Paste:=xlPasteValues, _
                Operation:=xlNone, _
                SkipBlanks:=False, _
                Transpose:=False
        End With
        .Columns("A:A").EntireColumn.AutoFit
    End With
    
    End Sub
    Suggest you post a sample workbook that demonstrates the problem.

  3. #3
    Registered User
    Join Date
    12-22-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    19

    Re: Paste Special Values losing destination formatting

    That didnt work either Its still pasting as General
    I guess i'll just have to format each column individually after pasting

    e.g.

    Range("A4:A100").NumberFormat = "dd/mm/yyyy"

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: Paste Special Values losing destination formatting

    You misunderstand. I'm not saying that code will work any differently. However, I recorded a simple macro which is shown first and then I "cleaned it up" to avoid ".Select ... Selection." Both versions, in my empty workbook, work as expected. That is, they copy a cell value, which happens to be a date, and pastes the value into another cell, which is formatted as a date.

    So, if that isn't happening for you, I suspect that the problem lies elsewhere. But, without seeing what you are working with, I cannot investigate or explain what is going wrong.

+ 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. How do I paste special values with Destination:=Worksheets
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2016, 01:11 PM
  2. Why am I losing my paste special menu????
    By teseract314 in forum Excel General
    Replies: 4
    Last Post: 04-01-2012, 02:55 AM
  3. [SOLVED] Excel VBA Paste Special - replace contents of destination cells
    By Sam via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2012, 12:44 PM
  4. Paste Special, replace contents of destination
    By Cookstein2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2009, 04:35 AM
  5. Paste to take destination formatting
    By jman0707 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2008, 12:21 PM
  6. Paste to take destination formatting
    By jman0707 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2008, 09:38 AM
  7. Paste Special Values but keep formatting and column widths
    By drdavidge in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2006, 01:00 PM

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