select all rows of a table except the first row

M

Mike B

Hi
I have a macro that does a bit of formatting to any table that the cursor is
placed in. I can select the whole table easily:

Selection.Tables(1).Select

and can select individual rows too:

Selection.Rows(1).Select

but I now need to select every row except the first one (2-x) where x could
be any number, depending on how big the table is. Maybe some way of counting
the rows in the table first (x) and then using that number to select rows
2-x? Or maybe select row 2, perform the action, and move to next row and
repeat until there are no more rows in table 1?
Any other suggestions?
What would the syntax be?
thanks.


Mike Bourke
Sales Information Designer

IBM New Zealand Limited
Internet email : (e-mail address removed)
+64 4 462 3534 DDI
+64 4 576 5615 fax
+64 21 679 746 mob
 
J

Jay Freedman

You can do this by manipulating the Selection object's .Start
property:

Sub demo1()
With Selection
.Tables(1).Select
.Start = Selection.Tables(1).Rows(2).Range.Start
.Font.Bold = True
End With
End Sub

Generally, it's a good idea to avoid using the Selection when all you
want to do is "a bit of formatting", because that also moves the
cursor and leaves the user wondering what happened. Instead, use a
Range object:

Sub demo2()
Dim myRange As Range
With Selection.Tables(1)
Set myRange = _
ActiveDocument.Range(.Rows(2).Range.Start, .Range.End)
End With
myRange.Bold = True
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Greg Maxey

Sub Scratchmacro()
Dim oRng As Word.Range
Dim oTbl As Word.Table
Set oTbl = Selection.Tables(1)
Set oRng = oTbl.Range
oRng.Start = oTbl.Cell(2, 1).Range.Start
oRng.Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top