PDA

View Full Version : [SOLVED:] Help with Pasting Values



nirvehex
04-02-2016, 01:46 PM
Hello,

I seem to not be able to get this piece of code to correctly paste values.



Sub Recommendation()
Sheets("Recommendation").Select
Dim lr As Long
lr = Cells(Rows.Count, 3).End(xlUp).Row
Application.ScreenUpdating = False
Range("C2:I5").Copy Cells(lr + 1, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range(Cells(lr + 1, 1), Cells(lr + 4, 1)).Value = Sheets("Data Table").Cells(Rows.Count, 1).End(xlUp).Value
Range(Cells(lr - 3, 1), Cells(lr, 14)).Copy
Range(Cells(lr + 1, 1), Cells(lr + 4, 14)).PasteSpecial Paste:=xlPasteFormats
Range(Cells(lr - 3, 10), Cells(lr, 10)).Copy Cells(lr + 1, 10)
Cells(lr - 3, 2).Copy Cells(lr + 1, 2)
Range(Cells(lr - 3, 11), Cells(lr, 11)).Copy Cells(lr + 1, 11)
Application.ScreenUpdating = True
End Sub



It's throwing an error on this line:



Range("C2:I5").Copy Cells(lr + 1, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


Any idea how to write this correctly?

Thanks!

Simon Lloyd
04-03-2016, 11:13 AM
Because this line
Range("C2:I5").Copy Cells(lr + 1, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
is NOT one line, it should look like this
Range("C2:I5").Copy
Cells(lr + 1, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode:= FALSE

nirvehex
04-03-2016, 11:28 AM
That worked. For some reason I had to take out the
Application.CutCopyMode:= FALSE at the end though. Thank you!

GTO
04-04-2016, 12:28 AM
Application.CutCopyMode = False

Just delete the colon and that line will remove the "marching ants".

snb
04-04-2016, 12:56 AM
You'd better use:


Cells(lr + 1, 3).resize(3,6)=Range("C2:I5").Value

nirvehex
04-09-2016, 01:37 PM
Thanks snb