Here is the code I have. I am trying to find the last populated row in a range. Then copy that data as formulas to the next blank row in the range. Finally copy the last populated row again and paste it to the second to last populated row as values. In a nutshell, move the formulas in the last row/cells down one row and retain that data where it was copied as numbers. So when new data is brought into the file, the formulas recalculate and I do not lose the previous calculated data. Hopefully that makes sense. The below code runs but does not appear to do anything other than to paste the data as values in the existing rows. What am I doing wrong?
Sub Data Copy()
Dim myLastCell As Range
Set myLastCell = LastCell(Worksheets("YTD Metric Calculator").Range("E7:J76"))
Sheets("YTD Metric Calculator").Range("E7:J" & myLastCell.Row).Copy
Sheets("YTD Metric Calculator").Range("E7:J" & myLastCell.Row + 1).PasteSpecial Paste:=xlPasteFormulas
Sheets("YTD Metric Calculator").Range("E7:J" & myLastCell.Row).Copy
Sheets("YTD Metric Calculator").Range("E7:J" & myLastCell.Row + 1).PasteSpecial Paste:=xlPasteValues
'Retain Yesterday's YTD Metric Data
Function LastCell(r As Range) As Range
Dim LastRow&, lastCol%
On Error Resume Next
With r
LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
lastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
End With
Set LastCell = r.Cells(LastRow&, lastCol%)
End Function
&
and%
, they are type identifiers -&
isLong
,%
isInteger
. Hangover from the really, really, old days whenAs Integer
etc didn't exist. – YowE3K