VBA, copy lines

R

Robert

Hi,

This morning I posted a question how to copy lines with a specific
value to an empty sheet.
I got a promt reaction including the below statement but when running
the macro I am getting an error on .Rows(i).Copy
Worksheets("Sheet2").Cells(INextrRow,"A")
Can someone tell me if this is a result of the fact that VB does not
know where to paste the first line? and if so can you please advice
how to solve this (including some sort of offset function)?

With Worksheets("Sheet1")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i,"A").Value = "CCC" Then
iNextRow = iNextRow + 1
.Rows(i).Copy
Worksheets("Sheet2").Cells(INextrRow,"A")
End If
Next i
End With



Many thanks for your willingness!

Rgds,
Robert
 
T

Tom Ogilvy

Bob replied to the original thread with a correction for the typo INextrRow
to INextRow

dim iLastRow as Long, iNextRow as Long
Dim i as Long
With Worksheets("Sheet1")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i,"A").Value = "CCC" Then
iNextRow = iNextRow + 1
.Rows(i).Copy _
Worksheets("Sheet2").Cells(INextRow,"A")
End If
Next i
End With
 
D

Don Guillett

Worksheets("Sheet2").Cells(INext r Row,"A")
however, I would have used

Worksheets("Sheet2").rows(INextRow)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top