Address Table Header Rows

  • Thread starter Michael Koerner
  • Start date
M

Michael Koerner

I have a number of tables that are created from merging Excel data I am
looking for a way to go through the document and when ever the first column
last name changes from A to B and B to C I would like to insert a new row,
merging all the cells with the new Alpha character centered, Bolded, and the
cell bordered on the outside. Any suggestions greatly appreciated.
 
D

Doug Robbins - Word MVP

The following macro should do what you want as long as the Lastname is the
first word in the cells of the first column.

Dim i As Long
Dim mytable As Table
Dim lname As Range
Dim Initial As String
Dim Alpha As String
Dim newrow As Row
Set mytable = ActiveDocument.Tables(1)
Alpha = " "
With mytable
For i = 1 To .Rows.Count
Set lname = .Cell(i, 1).Range
Initial = Left(lname.Text, 1)
If Initial <> Alpha Then
Alpha = Initial
Set newrow = mytable.Rows.Add(BeforeRow:=mytable.Rows(i))
newrow.Cells.Merge
newrow.Range.Text = Alpha
newrow.Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
newrow.Range.Font.Bold = True
i = i + 1
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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