VBA Rows.Copy Problem

beartooth91

Board Regular
Joined
Dec 15, 2024
Messages
64
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Not sure what I'm doing wrong here, its only pasting the last entry. There should be 6 lines pasted.

VBA Code:
Sub ForEa_Test()
'
With Worksheets("Combined")
  Dim Lrw As Long
  Lrw = .Cells(Rows.Count, "B").End(xlUp).Row

  For Each cell In .Range("B8:N" & Lrw)
    If cell.Value = "DI" Then
       cell.EntireRow.Copy Destination:=Sheets("New2").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    End If
  Next cell
End With
End Sub
 
This worked. Thanks. The only problem is I'm not understanding why my version didn't work. Your solution agrees with Fluff's post......I'm just not really understanding what Column A has to do with it......?
Unless..... Since Column A is empty.....its always finds the same start row and is pasting each entry over the previous.....
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi Fluff,

I suggested the solution detailed in post #7 because if you use the following code snippet
VBA Code:
cell.EntireRow.Copy Destination:=Sheets("New2").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)

I got the following error message:

Error in Copy_Screenshot 2025-01-01 210453.png


See you soon
 
Upvote 0

Forum statistics

Threads
1,225,623
Messages
6,186,063
Members
453,336
Latest member
Excelnoob223

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