sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm trying to loop through the non-blank cells in column A of a worksheet and then copy each of those values to another worksheet by using this;
It fails on this line and I don't know why;
I know that I can use a straight copy and paste but I will need to avoid that because once I've got this working I will need to add an IF statement if the value in the cell is a certain string.
Code:
'Import items
Set ws = DestFile.Sheets("HandoverSummary")
With DestFile.Sheets("HandoverItems")
Lastrow = Range("A65536").End(xlUp).Row
For Each cell In Range("A2:A" & Lastrow)
If cell <> "" Then
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = .Range("A" & cell).Value
End If
Next
End With
It fails on this line and I don't know why;
Code:
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
I know that I can use a straight copy and paste but I will need to avoid that because once I've got this working I will need to add an IF statement if the value in the cell is a certain string.