Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2014, 10:45 AM
konopca konopca is offline Find specific rows then copy and paste to new doc Windows XP Find specific rows then copy and paste to new doc Office 2003
Novice
Find specific rows then copy and paste to new doc
 
Join Date: Apr 2011
Posts: 27
konopca is on a distinguished road
Default Find specific rows then copy and paste to new doc

Hi everyone.
I have a table with two hundred plus rows. I would like to be able to find the rows that have the word "Draft" in the 3rd column. I then want to copy the entire row, loop through the rest of the table while finding and copying, and then paste into a new document.



I think it will have to be macro code and this is beyond my abilities.

The table is eight columns if that matters. The word Draft is not the only word in column 3. Oh and column 3 is a hyperlink but does not have to be pasted as a hyperlink.

Carol
Reply With Quote
  #2  
Old 02-16-2014, 04:34 PM
macropod's Avatar
macropod macropod is offline Find specific rows then copy and paste to new doc Windows 7 32bit Find specific rows then copy and paste to new doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Carol,

Try:
Code:
Sub Demo()
Dim DocSrc As Document, DocTgt As Document, Tbl As Table, TblRw As Row
Set DocSrc = ThisDocument
Set DocTgt = ActiveDocument
With DocSrc
  For Each Tbl In .Tables
    For Each TblRw In Tbl.Columns(3).Cells
      With TblRw.Range
        If InStr(.Text, "Draft") > 0 Then
          .Rows(1).Range.Copy
          DocTgt.Range.Characters.Last.Paste
        End If
      End With
    Next
  Next
End With
Set DocSrc = Nothing: Set DocTgt = Nothing
End Sub
Note: As coded, the source and target documents are specified as 'ThisDocument' and 'ActiveDocument', respectively. You'll need to make the appropriate modifications to the code if that's not the case.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-18-2014, 05:56 AM
konopca konopca is offline Find specific rows then copy and paste to new doc Windows XP Find specific rows then copy and paste to new doc Office 2003
Novice
Find specific rows then copy and paste to new doc
 
Join Date: Apr 2011
Posts: 27
konopca is on a distinguished road
Default

Thanks Paul - Tried it out but can't get it to work. I get a Run-time error #424. Obect Required.

The debugger stops at my file names which I changed as follows:
Set DocSrc = IndexSource.docx
Set DocTgt = IndexTarget.docx

Do I need the path?
Thanks for you help.
Reply With Quote
  #4  
Old 02-18-2014, 01:58 PM
macropod's Avatar
macropod macropod is offline Find specific rows then copy and paste to new doc Windows 7 32bit Find specific rows then copy and paste to new doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Those variable references are to documents, not just document names. The code I posted assumes you've opened the documents and therefore need only to tell the macro which is which. As coded, the macro assumes it is in the source document, which isn't the active one, and that the active document is the target document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-20-2014, 06:46 AM
konopca konopca is offline Find specific rows then copy and paste to new doc Windows XP Find specific rows then copy and paste to new doc Office 2003
Novice
Find specific rows then copy and paste to new doc
 
Join Date: Apr 2011
Posts: 27
konopca is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As coded, the macro assumes it is in the source document, which isn't the active one, and that the active document is the target document.
Hi Paul - Please excuse me, I'm confused by this statement. So I tried running the macro while I was in the IndexSource dcoument and then while I was in the IndexTarget document. I get the same error code regardless. My code is in my Normal template, maybe that's the problem?

Carol
Reply With Quote
  #6  
Old 02-20-2014, 02:34 PM
macropod's Avatar
macropod macropod is offline Find specific rows then copy and paste to new doc Windows 7 32bit Find specific rows then copy and paste to new doc Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You have two documents:
1. A source document
2. A target document
The macro is coded on the assumption that it is placed in the source document. Open the source document, press Alt-F11 to open the VBE, and add the macro to that document. Press Alt-F11 again to return to the document. Then open the target document (or, if it's already open, make that document the active one). Then press Alt-F11 to open the VBE, select the macro (in the source document) and press F5 to run it.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find specific rows then copy and paste to new doc Deleting rows with specific criteria joflow21 Excel 9 11-22-2013 12:10 PM
Why cant I just copy/paste new flippin rows into a flippin table? jethrouk Word 8 11-17-2013 06:09 PM
Find specific rows then copy and paste to new doc Paste Special: Copy and Paste Formatting Only? tinfanide Word 6 03-06-2013 12:21 AM
Find specific rows then copy and paste to new doc Find Results in excel copy the rows to another sheet khalidfazeli Excel 2 02-06-2013 09:38 AM
Find specific rows then copy and paste to new doc Find, copy and paste into a new page jperez84 Word VBA 24 09-20-2012 11:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft