VBA Copy & Paste last row with formula, then copy & Paste the row above as Value

Michaelstef

New Member
Joined
Jun 5, 2018
Messages
5
Dear Sir or Madam,
I am looking for a VBA Excel Makro with the following action:
I have an excel workbook with many sheets. They are all set-up the same way.
I need to copy&Past always the last row within a sheet with the formula and copy&Past thereafter the row above with Value within the same sheet.
Example:
C7:D7 pull formula to C8:D8
O7:o7 pull formula to o8:o8
r7:r7 pull formula to r8:r8
thereafter:
C7:D7 copy&past as values
O7:o7 copy&paste as values
r7:r7 copy&paste as values
It should always automaically go to the last row and has many sheets, alls set up the same way, besides the first sheet.
Thanks in advance for your support.
Best regards
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel
How about
Code:
Sub CopyFormulas()
   Dim ws As Worksheet
   Dim fnd As Range
   For Each ws In Worksheets
      Set fnd = ws.Cells.Find("*", , xlValues, , xlRows, xlPrevious, , , False)
      Set fnd = Intersect(ws.UsedRange, fnd.EntireRow).SpecialCells(xlFormulas)
      fnd.Resize(2).FillDown
      fnd.Value = fnd.Value
      Set fnd = Nothing
   Next ws
End Sub
 
Upvote 0
Hi Fluff
Thanks for your e-mail.
This formula unfortunately does not work. I have tried and found a way to copy down the last row:

Cells(Rows.Count, 3).End(xlUp).Copy
eRow = Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
Cells(eRow, 3).PasteSpecial xlPasteFormulas

Now I just need to copy & paste the row above the last row. How is this VBA code?

Thanks for your feedback.

Best regards

michael
 
Upvote 0
Hi

I tried this:

Cells(Rows.Count, 3).End(xlUp).Copy
cRow = Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
Cells(cRow, 3).PasteSpecial xlPasteFormulas
hRow = Cells(Rows.Count, 3).End(xlUp).Offset(-1, 0).Copy
Cells(hRow, 3).PasteSpecial xlPasteFormulas

But it somehow does not work. Can anyone help?

Thanks in advance for your feedback.

Best regards
 
Upvote 0
Sorry, it should read:

Cells(Rows.Count, 3).End(xlUp).Copy
cRow = Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
Cells(cRow, 3).PasteSpecial xlPasteFormulas
hRow = Cells(Rows.Count, 3).End(xlUp).Offset(-1, 0).Copy
Cells(hRow, 3).PasteSpecial xlPasteValues
 
Upvote 0
In what way didn't the code I supplied work?
 
Upvote 0
In what way didn't the code I supplied work?
Nothing happened. I but in now the following formula:

Code:
Sub Copy()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
         
Cells(Rows.Count, 3).End(xlUp).Copy
aRow = Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
Cells(aRow, 3).PasteSpecial xlPasteFormulas
Cells(Rows.Count, 3).End(xlUp).Offset(-1, 0).Copy
bRow = Cells(Rows.Count, 3).End(xlUp).Offset(-1, 0).Row
Cells(bRow, 3).PasteSpecial xlPasteValues
Cells(Rows.Count, 4).End(xlUp).Copy
aRow = Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).Row
Cells(aRow, 4).PasteSpecial xlPasteFormulas
Cells(Rows.Count, 4).End(xlUp).Offset(-1, 0).Copy
bRow = Cells(Rows.Count, 4).End(xlUp).Offset(-1, 0).Row
Cells(bRow, 4).PasteSpecial xlPasteValues
Cells(Rows.Count, 15).End(xlUp).Copy
aRow = Cells(Rows.Count, 15).End(xlUp).Offset(1, 0).Row
Cells(aRow, 15).PasteSpecial xlPasteFormulas
Cells(Rows.Count, 15).End(xlUp).Offset(-1, 0).Copy
bRow = Cells(Rows.Count, 15).End(xlUp).Offset(-1, 0).Row
Cells(bRow, 15).PasteSpecial xlPasteValues
Cells(Rows.Count, 18).End(xlUp).Copy
aRow = Cells(Rows.Count, 18).End(xlUp).Offset(1, 0).Row
Cells(aRow, 18).PasteSpecial xlPasteFormulas
Cells(Rows.Count, 18).End(xlUp).Offset(-1, 0).Copy
bRow = Cells(Rows.Count, 18).End(xlUp).Offset(-1, 0).Row
Cells(bRow, 18).PasteSpecial xlPasteValues
Next
End Sub

Is there a way to shorten this formula? This formula works now perfectly.

Thanks for your help.

Best regards
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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