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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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