Insert Copy and Paste with a formula

DBaker7777

Board Regular
Joined
Feb 3, 2009
Messages
53
Office Version
  1. 365
  2. 2016
I have the following code that works great. I want to add a formula to column S to Sheet2 each time a row is pasted. The formula would need to increment each time it is pasted.
Something like
=IF(L1>Sheet1!$A$1,"NEW","") and the Next formula that gets placed in should be =IF(L2>Sheet1!$A$1,"NEW,"") and so on . Any help would be greatly appreciated.


VBA Code:
Private Sub CommandButton2_Click()
Dim lastrow as long
lastrow=Sheets("Sheet2").Range("A655536").End(xlup).row+1
Activeworkbook.Sheets("Sheet1").Range("A1:R1").copy
Activeworkbook.Sheets("Sheet2").Range("A" & lastrow).pastespecial Paste=xlpastevalue
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
SQL:
Private Sub CommandButton2_Click()
    Dim lastrow As Long
    lastrow = Sheets("Sheet2").Range("A655536").End(xlUp).Row + 1
    ActiveWorkbook.Sheets("Sheet1").Range("A1:R1").Copy
    ActiveWorkbook.Sheets("Sheet2").Range("A" & lastrow).PasteSpecial Paste = xlpastevalue
   
    Dim str1 As String
' modify the next line according to your formula need changing lastrow if needed
    str1 = "=IF(L" + lastrow + ">Sheet1!$A$" + lastrow + ",""NEW"","""")"
    Sheets("Sheet2").Cells(lastrow, "S").Formula = str1

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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
Back
Top