Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default VBA, copy lines

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA, copy lines

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

--
Regards,
Tom Ogilvy


"Robert" wrote in message
oups.com...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy formula down 1000,s of lines gfj Excel Worksheet Functions 2 November 5th 08 08:40 PM
How do I copy just the collapsed subtotal lines? MTZgirl Excel Discussion (Misc queries) 3 November 2nd 07 09:32 PM
VBA, copy lines with specific value Robert[_30_] Excel Programming 3 February 13th 07 12:57 PM
Copy selected lines WTG Excel Worksheet Functions 9 February 17th 06 02:45 AM
Copy matching lines cbrd[_2_] Excel Programming 1 December 31st 05 02:42 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"