0

I have this code but I need it to copy paste the data as values. I know it probably is very simple, but I have not used .Paste function, so I do not know how to convert it. I am at a very beginner level. Many thanks in advance!

Sub Movetabletototal()
    Dim Count As Integer
    Dim copyRng As Range, pasteRng As Range
    Dim totalWS As Worksheet, mixerWS As Worksheet

    Set totalWS = Worksheets("TOTAL")
    Set mixerWS = Worksheets("MIXER TOTAL")

    Set copyRng = mixerWS.Range("P3:Q" & mixerWS.Cells(mixerWS.Rows.Count, 17).End(xlUp).Row)

    Dim newRow As Long
    newRow = totalWS.Cells(totalWS.Rows.Count, 1).End(xlUp).Row
    If newRow > 1 Then newRow = newRow + 1

    copyRng.Copy totalWS.Range(totalWS.Cells(newRow, 1), totalWS.Cells(newRow + copyRng.Rows.Count, copyRng.Columns.Count))
End Sub
1
  • 1
    Read PasteSpecial Method. Commented May 11, 2017 at 13:52

3 Answers 3

2

If you're only interested in the values there's no reason to use either Copy, Paste or PasteSpecial. Instead, just use a direct value assignment:

Dim destinationRange as Range
With totalWs
    Set destinationRange = .Cells(newRow, 1).Resize(copyRange.Rows.Count, copyRange.Columns.Count)
End With

destinationRange.Value = copyRange.Value
Sign up to request clarification or add additional context in comments.

Comments

1

You need to use PasteSpecial in your code. Change the last line to this:

'.
'. Your code will be the same till here
'.

copyRng.Copy

Set pasteRng = totalWS.Range(totalWS.Cells(newRow, 1), _
totalWS.Cells(newRow + copyRng.Rows.Count, copyRng.Columns.Count))

pasteRng.PasteSpecial xlPasteValues

End Sub

Or you can use values like below (set the ranges like above):

pasteRng.Value = copyRng.Value

2 Comments

How about using .value=.value instead copy-paste?
@Vinnie OP asks about using paste function. I personally prefer that method (Just check out my last question here and my own answer to it).
0

You could also try

.PASTESPECIAL (-4163)

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.