PDA

View Full Version : [SOLVED:] Help modifying "copying specific rows" code.



Kilroy
09-19-2016, 07:42 AM
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

gmaxey
09-19-2016, 11:15 AM
Answered here: http://www.vbaexpress.com/forum/showthread.php?57169-copying-specific-rows