Results 1 to 8 of 8

Thread: To Paste special by value

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Rep Power
    0

    To Paste special by value

    HI Team,

    I have the macro which opens the files from specified folder and pastes in a file one below another.But the problem is its doing copy paste but i need Paste special by value; Pleas find the below code which I'm using.

    PHP Code:
    'ThisWorkbook.Worksheets("Data").Clear
     '
    On Error Resume Next
     Workbooks
    .Open Filename:=ThisWorkbook.Worksheets("Main").Cells(i1)
     
     
    ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy Destination:=ThisWorkbook.Worksheets("Upload").Cells(j"A")
     
      
    ActiveWorkbook.Close
     j 
    100
     
     Application
    .Wait Now TimeValue("00:00:05")
     
    Next i
      ThisWorkbook
    .Worksheets("Data").Visible False
     
    End Sub 
    Please help me to turn the result in paste special by value.

    Thanks in Advance.
    Last edited by ravichandavar; 08-11-2013 at 05:18 AM.

  2. #2
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0

    Import data as values

    Hi ravichandavar,

    Try replacing this line...

    Code:
    ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy Destination:=ThisWorkbook.Worksheets("Upload").Cells(j, "A")
    ...with these lines:

    Code:
    ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy
        ThisWorkbook.Worksheets("Upload").Cells(j, "A").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    Regards,

    Robert

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    12
    Rep Power
    0
    Hi Robert,

    Thanks for the quick solution. Its working fine.

    Regards,
    Ravi.C

  4. #4
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    Thanks for the feedback and you're welcome

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by Trebor76 View Post
    Hi ravichandavar,

    Try replacing this line...

    Code:
    ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy Destination:=ThisWorkbook.Worksheets("Upload").Cells(j, "A")
    ...with these lines:

    Code:
    ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy
        ThisWorkbook.Worksheets("Upload").Cells(j, "A").PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    Alternately, you could do the same thing with this single line of code...

    Code:
    ThisWorkbook.Worksheets("Upload").Cells(j, "A").Range("A1:O100").Value = ActiveWorkbook.ActiveSheet.Range("A1:O100").Value
    I am not 100% sure of how your setup looks, but I am pretty sure you do not need the part of the code I highlighted in red and I am not so sure whether you need the part of your code I highlighted in blue either.
    Last edited by Rick Rothstein; 08-12-2013 at 10:33 PM.

  6. #6
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    Hi Rick,

    Yes, well put. I had considered that code too but thought the original formatting may have been important so I didn't recommend that method. If formatting isn't an issue, then I would recommend Ravi uses your code.

    Cheers,

    Robert

  7. #7
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by Trebor76 View Post
    Hi Rick,

    Yes, well put. I had considered that code too but thought the original formatting may have been important so I didn't recommend that method. If formatting isn't an issue, then I would recommend Ravi uses your code.
    But you used PasteSpecial and specified xlPasteValues for the Paste argument... only the cell values will get copied with your code, the formatting will be lost. As far as I know, both your 3-line code snippet and my one-liner will produce the same identical output.

  8. #8
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    But you used PasteSpecial and specified xlPasteValues for the Paste argument... only the cell values will get copied with your code, the formatting will be lost. As far as I know, both your 3-line code snippet and my one-liner will produce the same identical output.
    Yes, thanks Rick - spot on (again).

    Ravi, if you want the formatting as well as the value, use this...

    Code:
        ActiveWorkbook.ActiveSheet.Range("A1:O100").Copy
        With ThisWorkbook.Worksheets("Upload").Cells(j, "A")
            .PasteSpecial Paste:=xlPasteValues
            .PasteSpecial Paste:=xlPasteFormats
        End With
        Application.CutCopyMode = False
    ...or if it's just the values use Rick's solution (you can of course still use mine but 1 line is better than 3!!)

    Regards,

    Robert

Similar Threads

  1. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  2. Macro Copy Columns and Paste in rows.
    By TommyKris in forum Excel Help
    Replies: 3
    Last Post: 03-06-2013, 02:36 PM
  3. Replies: 2
    Last Post: 02-23-2013, 09:18 PM
  4. VBA -- Copy/Paste across sheets
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 09-21-2012, 02:07 PM
  5. Remove Special Characters :
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 03-06-2012, 09:41 PM

Posting Permissions

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