PC Review


Reply
Thread Tools Rate Thread

Copying and pasting rows from one wksht to another based on cell v

 
 
PVANS
Guest
Posts: n/a
 
      22nd Mar 2010
Good morning

Was wondering if someone had a suggestion for me with regards to this, I
have the following code that is copying rows from Worksheet1 ("Working") and
adding them to another worksheet in the same workbook called "March":

Set SrcSht = Sheets("Working")
Set DstSht = Sheets("MARCH")
LastrowA = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastrowB = DstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
SrcSht.Range("A1:A" & LastrowA).EntireRow.Copy DstSht.Cells(LastrowB, 1)

I would like to now copy only specific rows based on their value in column Q
and add them to another worksheet in the workbook. I edited the code as
follows, however, it does not seem to work:

Dim LastrowA As Long
Dim LastrowB As Long
Set SrcSht = Sheets("Working")
Set DstSht = Sheets("Sheet3")
LastrowA = SrcSht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row
LastrowB = DstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1

For q = SrcSht.Range("q65536").End(xlUp).Row To 1 Step -1
If SrcSht.Cells(q, 17) = "cw" Then
SrcSht.Rows(q).Copy DstSht.Cells(LastrowB, 1)
End If
Next

It seems to simply copy the necessary rows onto the same line, thus leaving
me with only one line on Worksheet3. Can someone suggest why this is
happening, and a method to fix it?

Thank you so much

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and paste rows from one wksht to another based on cell value PVANS Microsoft Excel Programming 3 22nd Mar 2010 12:09 PM
1st 2 rows of wksht show up @ top of each page of the wksht Remote Paralegal Microsoft Excel Misc 2 6th Oct 2008 07:59 PM
macro to paste certain cell formats based on wksht name =?Utf-8?B?YXBzMTMxNQ==?= Microsoft Excel Programming 1 11th Jul 2005 06:41 PM
Copying rows of data based on a value in a cell. Screamerz Microsoft Excel Programming 4 16th Dec 2004 01:40 PM
copying rows based on cell value Ronnie Microsoft Excel Programming 9 16th Mar 2004 05:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:12 PM.