kenchristensen11
Board Regular
- Joined
- Oct 12, 2016
- Messages
- 52
Hello,
I have the below code but after it copies the entire row to the target sheet, the formulas are still there.
What I need to it do is Paste them as values (to get rid of the formula) after it's copied to the target sheet, BUT also keep formatting the same from the source sheet.
I have the below code but after it copies the entire row to the target sheet, the formulas are still there.
What I need to it do is Paste them as values (to get rid of the formula) after it's copied to the target sheet, BUT also keep formatting the same from the source sheet.
VBA Code:
Sub MoveRowsToArchive()
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Quarterly Prep")
Set targetSheet = ThisWorkbook.Worksheets("Archive")
' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "B").End(xlUp).Row
' Loop through each row in the source sheet
For i = 9 To lastRow
' Check if cell in column X contains "Archive"
If sourceSheet.Cells(i, "B").Value = "Archive" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
' Delete the row from the source sheet
sourceSheet.Rows(i).Delete
' Decrement the loop counter as the rows are shifting up
i = i - 1
' Update the last row value
lastRow = lastRow - 1
End If
Next i
End Sub