+ Reply to Thread
Results 1 to 5 of 5

help copying cell value instead of formula

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    help copying cell value instead of formula

    I'm using this code to copy selected rows to another sheet but I want to just copy the value and not the formula. I'm useing "Copy Destination:=ws1.Cells" but is there a way to paste value?

    Formula: copy to clipboard
    Private Sub commandbutton2_click()

    'adds selected rows to information that already exists on protocol sheet - instead of overwriting them
    Dim i As Integer
    Dim j As Integer
    Dim aRow As Long
    Dim jRow As Long
    Dim lRow As Long
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    Set ws1 = Sheets("protocol")
    Set ws = Sheets("coherence")
    aRow = ws.Cells(Rows.Count, "a").End(xlUp).Row ' how many selections in column A
    jRow = ws1.Cells(Rows.Count, "l").End(xlUp).Row ' how many rows are already filled in protocol sheet
    lRow = ws.Cells(Rows.Count, "l").End(xlUp).Row 'how many selections in column l
    j = jRow + 1 ' which row to place data on protocol sheet


    With ws
    For i = 3 To aRow
    If .Cells(i, 1) = "X" Then 'where to look for true - offset one right from linked cell of toggle switch - coherence
    .Cells(i, 2).Resize(, 9).Copy Destination:=ws1.Cells(j, 12) ' start pasting cells at J down, 12 across
    j = j + 1
    End If
    Next i
    For i = 3 To lRow
    If .Cells(i, 12) = "X" Then 'where to look for true - offset one right from linked cell of toggle switch - coherence
    .Cells(i, 13).Resize(, 9).Copy Destination:=ws1.Cells(j, 12) ' start pasting cells at J down, 12 across
    j = j + 1
    End If
    Next i
    End With
    Worksheets("protocol").Range("l5:t100").RemoveDuplicates Columns:=Array(1, 1)



    End Sub
    Last edited by kevinu; 05-23-2017 at 01:09 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: help copying cell value instead of formula

    To paste values only, you will need 2 lines for the copy/paste. For example:

    .Cells(i, 2).Resize(, 9).Copy Destination:=ws1.Cells(j, 12)
    becomes:
    .Cells(i, 2).Resize(, 9).Copy
    ws1.Cells(j, 12).PasteSpecial xlPasteValues
    Alternatively, keep the code the way you have it, and just make the value of the range in question = the .Value of the range... for example if A1 to A6 are the result of a formula, then Range("A1:A6").Value = Range("A1:A6").Value would convert the formulas to values
    Last edited by Arkadi; 05-23-2017 at 01:14 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: help copying cell value instead of formula

    thanks that worked great.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: help copying cell value instead of formula

    Glad I could help
    Thanks for the rep, and for marking the thread as solved.

  5. #5
    Forum Contributor
    Join Date
    03-10-2017
    Location
    USA
    MS-Off Ver
    office 2016
    Posts
    393

    Re: help copying cell value instead of formula

    I'm getting an error but I think im supposed to post a new thread instead of continuing on this one so I'll do that.

    Edit: problem solved. I noticed that the second For statement worked fine so I just erased the first For statement and rewrote the second to match the first then rewrote the second and now it all works. Seems nonsensical but somehow it did the trick. In the end its the exact same code as above. Here is the new code with the paste function.

    Formula: copy to clipboard
    rivate Sub commandbutton2_click()

    'adds selected rows to information that already exists on protocol sheet - instead of overwriting them
    Dim i As Integer
    Dim j As Integer
    Dim aRow As Long
    Dim jRow As Long
    Dim lRow As Long
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    Set ws1 = Sheets("protocol")
    Set ws = Sheets("coherence")
    aRow = ws.Cells(Rows.Count, "a").End(xlUp).Row ' how many selections in column A
    jRow = ws1.Cells(Rows.Count, "l").End(xlUp).Row ' how many rows of are already filled in protocol sheet
    lRow = ws.Cells(Rows.Count, "l").End(xlUp).Row 'how many selections in column l
    j = jRow + 1 ' which row to place data on protocol sheet


    With ws
    For i = 3 To aRow
    If .Cells(i, 1) = "X" Then 'where to look for true - offset one right from linked cell of toggle switch - coherence
    .Cells(i, 2).Resize(, 9).Copy 'Destination:=ws1.Cells(j, 12)
    ws1.Cells(j, 12).PasteSpecial xlPasteValues ' start pasting cells at J down, 12 across
    j = j + 1
    End If
    Next i
    For i = 3 To lRow
    If .Cells(i, 12) = "X" Then
    .Cells(i, 13).Resize(, 9).Copy
    ws1.Cells(j, 12).PasteSpecial xlPasteValues
    j = j + 1
    End If
    Next i
    End With
    Worksheets("protocol").Range("l5:t100").RemoveDuplicates Columns:=Array(1, 1)



    End Sub
    Last edited by kevinu; 05-26-2017 at 10:29 AM.

+ 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] Copying formula result to new cell, without copying formula itself
    By nappyjim1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2016, 02:24 AM
  2. Replies: 1
    Last Post: 02-03-2015, 06:44 AM
  3. [SOLVED] Retaining formula cell references when copying a formula to a different cell
    By FrankParisi in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-06-2013, 07:05 AM
  4. [SOLVED] copying cell without removing formula from the cell i copied from
    By raffi123 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-18-2013, 10:09 AM
  5. Replies: 1
    Last Post: 04-06-2013, 12:22 AM
  6. Replies: 7
    Last Post: 10-31-2012, 05:21 AM
  7. Copying formula to new cell
    By pakiplayer421 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2007, 05:54 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