+ Reply to Thread
Results 1 to 5 of 5

VBA Code To Change Pasted Cells as Values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-22-2003
    Location
    Newport, Rhode Island
    MS-Off Ver
    Excel 365
    Posts
    158

    VBA Code To Change Pasted Cells as Values

    Hello Everyone,
    Using Excel 2010

    I have a workbook that copies certain cells from sheet J1 (which are colored and have formulas) and paste them into cells in sheet Jan01. The code works but I need to have the pasted cells pasted as values. Appreciate any help adjusting the code to make them pasted cells. Thanks.
    Mike

    Sub Test()
        Application.ScreenUpdating = False
        With Sheets("J1")
            .Range("A2:A3").Copy Sheets("Jan01").Range("O12:O13")
            .Range("B2:B3").Copy Sheets("Jan01").Range("Q12:Q13")
            .Range("D2:D3").Copy Sheets("Jan01").Range("O16:O17")
            .Range("E2:E3").Copy Sheets("Jan01").Range("Q16:Q17")
             End With
    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: VBA Code To Change Pasted Cells as Values

    Could try

    Sheets("Jan01").Range("O12") = .Range("A2")
    etc.
    Martin

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,043

    Re: VBA Code To Change Pasted Cells as Values

    You are copying on same cells so it will be overwritten.

    for values use:

     Sub Test()
        Application.ScreenUpdating = False
        With Sheets("J1")
            .Range("A2:A3").Copy Sheets("Jan01").Range("O12:O13")
            .Range("B2:B3").Copy Sheets("Jan01").Range("Q12:Q13")
            .Range("D2:D3").Copy Sheets("Jan01").Range("O16:O17")
            .Range("E2:E3").Copy Sheets("Jan01").Range("Q16:Q17")
             End With
    
    with Sheets("Jan01")
    .Range("O12:O13").value = .Range("O12:O13").value
    .Range("Q16:Q17").value = .Range("Q16:Q17").value
    end with
    
    Application.ScreenUpdating = True
    End Sub
    Don't forget return Screenupdating at the end.
    Never use Merged Cells in Excel

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA Code To Change Pasted Cells as Values

    Try this
    With Sheets("J1")
            Sheets("Jan01").Range("O12:O13").Value = .Range("A2:A3").Value
            Sheets("Jan01").Range("Q12:Q13").Value = .Range("B2:B3").Value
            Sheets("Jan01").Range("O16:O17").Value = .Range("D2:D3").Value
            Sheets("Jan01").Range("Q16:Q17").Value = .Range("E2:E3").Value
    End With
    I also note that in both this and the OP code, every other line overwrites what was done in the preceding line.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    11-22-2003
    Location
    Newport, Rhode Island
    MS-Off Ver
    Excel 365
    Posts
    158

    Re: VBA Code To Change Pasted Cells as Values

    Thanks to all for the quick replies. I went with mikerickson.

+ 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. [SOLVED] Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-10-2013, 11:16 AM
  2. Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  3. Replies: 1
    Last Post: 07-07-2005, 10:05 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