Excel Macro Paste Special Value

mrkit

New Member
Joined
Nov 30, 2017
Messages
10
Hi,

I have a macro below which is copy and pasting cells from another worksheet.

I'm trying to update it so it will do paste special. if I use PasteSpecial xlPasteValues at the end of each row I am getting an Compile Error: Expected:end of statement error message.

Below is the full script.

How would I be able to change it so it would do paste special values?

Thanks.

Private Sub Copy_Existing_Asset_Click()


Dim i As Long
Dim iLastRow As Long
Dim iTarget As Long

With Worksheets("fleet")

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "Capex" Then
iTarget = iTarget + 1
.Cells(i, "B").Copy Worksheets("Sheet7").Range("A" & iTarget + 1)
.Cells(i, "C").Copy Worksheets("Sheet7").Range("B" & iTarget + 1)
.Cells(i, "D").Copy Worksheets("Sheet7").Range("C" & iTarget + 1)
.Cells(i, "E").Copy Worksheets("Sheet7").Range("D" & iTarget + 1)
.Cells(i, "F").Copy Worksheets("Sheet7").Range("F" & iTarget + 1)
Worksheets("Sheet7").Range("G" & iTarget + 1).Value = "Expenditure"
Worksheets("Sheet7").Range("H" & iTarget + 1).Value = "Depn & Loss on Sale"
Worksheets("Sheet7").Range("I" & iTarget + 1).Value = "2.62"
Worksheets("Sheet7").Range("J" & iTarget + 1).Value = "Depreciation Expense"
.Cells(i, "N").Copy Worksheets("Sheet7").Range("K" & iTarget + 1)
.Cells(i, "O").Copy Worksheets("Sheet7").Range("L" & iTarget + 1)
.Cells(i, "P").Copy Worksheets("Sheet7").Range("M" & iTarget + 1)
.Cells(i, "Q").Copy Worksheets("Sheet7").Range("N" & iTarget + 1)
.Cells(i, "R").Copy Worksheets("Sheet7").Range("O" & iTarget + 1)
End If
Next i

End With


With Worksheets("Property")

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "Capex" Then
iTarget = iTarget + 1
.Cells(i, "B").Copy Worksheets("Sheet7").Range("A" & iTarget + 1)
.Cells(i, "C").Copy Worksheets("Sheet7").Range("B" & iTarget + 1)
.Cells(i, "D").Copy Worksheets("Sheet7").Range("C" & iTarget + 1)
.Cells(i, "F").Copy Worksheets("Sheet7").Range("D" & iTarget + 1)
.Cells(i, "G").Copy Worksheets("Sheet7").Range("F" & iTarget + 1)
Worksheets("Sheet7").Range("G" & iTarget + 1).Value = "Expenditure"
Worksheets("Sheet7").Range("H" & iTarget + 1).Value = "Depn & Loss on Sale"
Worksheets("Sheet7").Range("I" & iTarget + 1).Value = "2.62"
Worksheets("Sheet7").Range("J" & iTarget + 1).Value = "Depreciation Expense"
.Cells(i, "R").Copy Worksheets("Sheet7").Range("K" & iTarget + 1)
.Cells(i, "S").Copy Worksheets("Sheet7").Range("L" & iTarget + 1)
.Cells(i, "T").Copy Worksheets("Sheet7").Range("M" & iTarget + 1)
.Cells(i, "U").Copy Worksheets("Sheet7").Range("N" & iTarget + 1)
.Cells(i, "V").Copy Worksheets("Sheet7").Range("O" & iTarget + 1)
End If
Next i

End With


With Worksheets("Other Capex")

iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, "A").Value = "Capex" Then
iTarget = iTarget + 1
.Cells(i, "B").Copy Worksheets("Sheet7").Range("A" & iTarget + 1)
.Cells(i, "C").Copy Worksheets("Sheet7").Range("B" & iTarget + 1)
.Cells(i, "D").Copy Worksheets("Sheet7").Range("C" & iTarget + 1)
.Cells(i, "E").Copy Worksheets("Sheet7").Range("D" & iTarget + 1)
.Cells(i, "F").Copy Worksheets("Sheet7").Range("F" & iTarget + 1)
Worksheets("Sheet7").Range("G" & iTarget + 1).Value = "Expenditure"
Worksheets("Sheet7").Range("H" & iTarget + 1).Value = "Depn & Loss on Sale"
Worksheets("Sheet7").Range("I" & iTarget + 1).Value = "2.62"
Worksheets("Sheet7").Range("J" & iTarget + 1).Value = "Depreciation Expense"
.Cells(i, "N").Copy Worksheets("Sheet7").Range("K" & iTarget + 1)
.Cells(i, "O").Copy Worksheets("Sheet7").Range("L" & iTarget + 1)
.Cells(i, "P").Copy Worksheets("Sheet7").Range("M" & iTarget + 1)
.Cells(i, "Q").Copy Worksheets("Sheet7").Range("N" & iTarget + 1)
.Cells(i, "R").Copy Worksheets("Sheet7").Range("O" & iTarget + 1)
End If
Next i

End With


MsgBox ("Existing Asset Copy & Paste Complete")

End Sub
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,974
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
If using PasteSpecial you need to put the copy and paste on separate lines all the way though your code i.e.
Code:
.Cells(i, "B").Copy Worksheets("Sheet7").Range("A" & iTarget + 1)
would become
Code:
.Cells(i, "B").Copy 
Worksheets("Sheet7").Range("A" & iTarget + 1).PasteSpecial xlPasteValues
 

Watch MrExcel Video

Forum statistics

Threads
1,127,355
Messages
5,624,207
Members
416,017
Latest member
moritz210

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top