Consulting

Results 1 to 2 of 2

Thread: Help modifying "copying specific rows" code.

  1. #1
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location

    Help modifying "copying specific rows" code.

    Greg wrote this code that is perfect for what I asked for and I'm super grateful. However I've come across a scenario where there is more than one table in my check list. I've tried changing the "Set oTbl = oDoc.Tables(1)" to (1,5), I've tried copying and pasting the same code 5 times and changing to "Set oTbl = oDoc.Tables(2)then (3)" and so on but I can't get it to work. Is there a way to get it recognize each of the tables no matter how many there are?

    Sub ScratchMacro() 
         'A basic Word macro coded by Greg Maxey
        Dim oDoc As Document 
        Dim oTbl As Table 
        Dim oCell As Cell 
        ActiveDocument.Range.Copy 
        Set oDoc = Documents.Add 
        oDoc.Range.Paste 
        Set oTbl = oDoc.Tables(1) 
        For Each oCell In oTbl.Range.Cells 
            If oCell.Range.Information(wdEndOfRangeColumnNumber) = 4 Then 
                If oCell.Range.Information(wdEndOfRangeRowNumber) > 2 Then 
                    If Left(oCell.Range, Len(oCell.Range) - 2) <> "N" And _ 
                    Left(oCell.Range, Len(oCell.Range) - 2) <> vbNullString Then 
                        oCell.Select 
                        Selection.Rows.Delete 
                    End If 
                End If 
            End If 
        Next 
    lbl_Exit: 
        Exit Sub 
    End Sub

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •