VBA Copy entire row then paste values

JonathanOTAX

New Member
Joined
May 10, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have this script;

VBA Code:
Sub copyrows()
 Dim tfCol As Range, Cell As Object
 
 Set tfCol = Range("G2:G999")
 
    For Each Cell In tfCol
      
      If Cell = "" Then
      ElseIf Cell.Value = 0 Then
         Cell.EntireRow.Copy
         Sheet4.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      Else
         Cell.EntireRow.Copy
         Sheet2.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.Paste
      End If
      
   Next
End Sub

However, I need to paste values. I tried simply shanging it to;

VBA Code:
Sub copyrows()
 Dim tfCol As Range, Cell As Object
 
 Set tfCol = Range("G2:G999")
 
    For Each Cell In tfCol
      
      If Cell = "" Then
      ElseIf Cell.Value = 0 Then
         Cell.EntireRow.Copy
         Sheet4.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.PasteSpecial xlPasteValues
      Else
         Cell.EntireRow.Copy
         Sheet2.Select
         ActiveSheet.Range("A65536").End(xlUp).Select
         Selection.Offset(1, 0).Select
         ActiveSheet.PasteSpecial xlPasteValues
      End If
      
   Next
End Sub

However, I get this error when I run it;
la83dqx.png


Any help would be appreciated. :)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try:
VBA Code:
Sub copyrows()
    Application.ScreenUpdating = False
    Dim tfCol As Range, Cell As Object
    Set tfCol = Range("G2:G999")
       For Each Cell In tfCol
         If Cell = "" Then
         ElseIf Cell.Value = 0 Then
            Cell.EntireRow.Copy
            Sheet4.Cells(Sheet4.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
         Else
            Cell.EntireRow.Copy
            Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
         End If
      Next
      Application.CutCopyMode = False
      Application.ScreenUpdating = True
End Sub
 
Upvote 0
How about
VBA Code:
Sub copyrows()
 Dim tfCol As Range, Cell As Object
 
 Set tfCol = Range("G2:G999")
 
    For Each Cell In tfCol
      
      If Cell = "" Then
      ElseIf Cell.Value = 0 Then
         Cell.EntireRow.Copy
         Sheet4.Range("A65536").End(xlUp).Offset(1).PasteSpecial xlPasteValues
      Else
         Cell.EntireRow.Copy
         Sheet2.Range("A65536").End(xlUp).Offset(1).PasteSpecial xlPasteValues
      End If
      
   Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

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