Copy row based on cell value and paste as text in another worksheet

DH937

New Member
Joined
Feb 12, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am wanting to cut an entire row and paste it into a new worksheet based on a cell value. I can currently do that but the problem I am having is when it goes into the new work sheet it is keeping the formulas, but I only want the formula result/text value. I have searched online and tried the PasteSpecial command within the current code I am using but cannot seem to get it to work.

Any help is greatly appreciated, thank you!



Sub MoveRowsToPendingReceipt()
Sheet1.Unprotect Password:="A6905"
Sheet2.Unprotect Password:="A6905"
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("Data Entry")
Set targetSheet = ThisWorkbook.Worksheets("Pending Receipt")

' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "F").End(xlUp).Row

' Loop through each row in the source sheet
For i = 2 To lastRow
' Check if cell in column F contains "Complete"
If sourceSheet.Cells(i, "F").Value = "Complete" 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
Worksheets("Pending Receipt").Range("B2:E1000").Locked = True
Sheet1.Protect Password:="A6905"
Sheet2.Protect Password:="A6905"
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Modify using a Destination Range
VBA Code:
Sub MoveRowsToPendingReceipt()
Sheet1.Unprotect Password:="A6905"
Sheet2.Unprotect Password:="A6905"
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet
Dim Destrng As Range
Dim lastRow As Long
Dim i As Long

' Set the source and target sheets
Set sourceSheet = ThisWorkbook.Worksheets("Data Entry")
Set targetSheet = ThisWorkbook.Worksheets("Pending Receipt")

Set Destrng = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)

' Find the last row in the source sheet
lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "F").End(xlUp).Row

' Loop through each row in the source sheet
For i = 2 To lastRow
' Check if cell in column F contains "Complete"
If sourceSheet.Cells(i, "F").Value = "Complete" Then
' Copy the entire row to the target sheet
sourceSheet.Rows(i).Copy 
'Destination:=targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Offset(1)
 Destrng.PasteSpecial xlPasteValues
' 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
Worksheets("Pending Receipt").Range("B2:E1000").Locked = True
Sheet1.Protect Password:="A6905"
Sheet2.Protect Password:="A6905"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,216,500
Messages
6,131,015
Members
449,615
Latest member
Nic0la

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