Copy Rows and Paste Special to New Worksheet

ab0511

New Member
Joined
Dec 22, 2020
Messages
2
Platform
  1. Windows
Currently I have:
Set xRgS = Range("$A:$A")
If xRgS Is Nothing Then Exit Sub
Set xRgD1 = Range("'Sheet2'!$E$2")
If xRgD1 Is Nothing Then Exit Sub
Set xRgD = Range("'Sheet2'!$A$2")
If xRgD Is Nothing Then Exit Sub
xCol = xRgS.Rows.Count
Set xRgS = xRgS(1)
Application.CutCopyMode = False
J = 0
For I = 1 To xCol
Set xCell = xRgS.Offset(I - 1, 0)
xVal = xCell.Value
If TypeName(xVal) = "Date" And (xVal <> "") And (xVal = Date) Then
xCell.EntireRow.Range("A1:D1").Copy xRgD.Offset(J, 0)
xCell.EntireRow.Range("J1:K1").Copy xRgD1.Offset(J, 0)
J = J + 1
End If
Next
Application.CutCopyMode = True
End Sub

which works if the cells I'm copying are just a value but I updated Sheet1 to have Formulas in columns J&K and I need to paste those as values to the new worksheet. I have tried a bunch of manipulations (one shown below) with the PasteSpecial but I can't seem to get this to work. Any recommendations?

Set xRgS = Range("$A:$A")
If xRgS Is Nothing Then Exit Sub
Set xRgD1 = Range("'Sheet2'!$E$2")
If xRgD1 Is Nothing Then Exit Sub
Set xRgD = Range("'Sheet2'!$A$2")
If xRgD Is Nothing Then Exit Sub
xCol = xRgS.Rows.Count
Set xRgS = xRgS(1)
Application.CutCopyMode = False
J = 0
For I = 1 To xCol
Set xCell = xRgS.Offset(I - 1, 0)
xVal = xCell.Value
If TypeName(xVal) = "Date" And (xVal <> "") And (xVal = Date) Then
xCell.EntireRow.Range("A1:D1").Copy xRgD.Offset(J, 0)
xCell.EntireRow.Range("J1:K1").Copy xRgD1.Offset(J, 0).PasteSpecial(xlPasteValue)
J = J + 1
End If
Next
Application.CutCopyMode = False
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You need to put it on two lines like
VBA Code:
xCell.EntireRow.Range("J1:K1").Copy
xRgD1.Offset(J, 0).PasteSpecial(xlPasteValue)
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

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