PC Review


Reply
Thread Tools Rate Thread

Copy & paste rows after found text to different wb and delete them

 
 
goaljohnbill
Guest
Posts: n/a
 
      3rd Jul 2008
I have a table as follows

Animal ID Tube # PRVg1 Result date
2008019881 55717 0.86 Neg 6/17/2008
2008019881 55718 0.999 Neg 6/17/2008
2008019881 55719 0.986 Pos! 6/17/2008
2008019881 55719 0.986 Neg 6/17/2008
2008019881 55720 0.929 Neg 6/17/2008
2008019881 55721 0.951 Neg 6/17/2008
2008019881 55722 0.96 Pos! 6/17/2008
2008019881 55722 0.96 Neg 6/17/2008
2008019881 55723 0.985 Neg 6/17/2008
2008019881 55724 0.983 Neg 6/17/2008

I need to be able to find each 1st Pos! result, go to the next record
in line (the dup tube number) copy that to a different wb, and delete
the copied line. I attemped to modify code greg wilson posted much
earlier to do so as follows. Somthing is wrong in the loop construct,
it wont end because it appears to "stay on" the second value, there
are possibly other errors after that also (such as the union):

Set MyRange = Selection
With MyRange
Set P = .find(What:="Pos!", LookIn:=xlValues, LookAt:=xlWhole,
_
SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
'''''
' 1st pos is "marked" to show loop stop point
'''''
If Not P Is Nothing Then
FirstAddress = P.Address
'''''
' set range ref to cell for union to create list
'''''
P.Select
ActiveCell.Offset(1, 0).Select
Set DeleteRng = ActiveCell
'''''
' activate row, CnP to rt list
'''''
ActiveCell.EntireRow.Select
Selection.Copy
Windows("i_PRVRT daily.xls").Activate
Range("A65515").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Windows("b_PRVAllPaste daily.xls").Activate
'''''
' setting p2 as find next p allows loop and
movement down from next pos!
' union builds list of ranges loops while there
are records
' that havnt already been checked
'''''
Do
Set P2 = .FindNext(P)
SecondAddress = P2.Address
If SecondAddress <> FirstAddress Then
P2.Select
ActiveCell.Offset(1, 0).Select
Set DeleteRng = Union(DeleteRng, P2, P)
ActiveCell.EntireRow.Select
Selection.Copy
Windows("i_PRVRT daily.xls").Activate
Range("A65515").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Windows("b_PRVAllPaste daily.xls").Activate
Else
End If
Loop While Not P2 Is Nothing And P2.Address <>
FirstAddress
End If
End With
'''''
' deletes rows of all records from union list
' saves and closes correct files
'''''
DeleteRng.EntireRow.Delete

Also I realized while messing with this that the find value Pos! could
also occur in the duplicate record and I wouldnt want it treated the
same, is there some way to "redraw" the range so that it would start
after the previous copied record to be erased?

thanks
john
 
Reply With Quote
 
 
 
 
goaljohnbill
Guest
Posts: n/a
 
      3rd Jul 2008
A thought just occurred to me that i will work on... could i do a For
Each to the ranges in "DeleteRng" to do all of the record manipulation
after finding all of the Pos! records?
 
Reply With Quote
 
goaljohnbill
Guest
Posts: n/a
 
      3rd Jul 2008
This appears it will work sorry to bother

john
 
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
Excel VBA - How to copy rows found & to cater if no rows found via autofilter kazzy Microsoft Excel Discussion 1 17th Feb 2011 02:10 AM
Can't delete or copy/paste rows in a worksheet that has lists assi Michelle M Microsoft Excel Crashes 1 5th Mar 2009 05:49 PM
Re: subtotal copy-paste and delete hidden rows Dave Peterson Microsoft Excel Misc 0 12th Dec 2006 03:26 PM
Copy/Paste rows with specifc text in column d Mike Woodard Microsoft Excel Programming 2 8th Mar 2006 08:54 PM
Copy/Paste Rows that Contain Specific Text Mike Woodard Microsoft Excel Worksheet Functions 1 8th Mar 2006 07:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.