For rows 2 & 3
start in cell 3
For 1 to x (x is a known variable)
add a bottom border to the cell
now merge this cell with the next n cells (n is a known variable)
increment variables to move to the next cell to be bordered and merged
next x
next row
I'll give my (rubbish) code in a minute but first I'll step though what is happening:
1) on entering the For rows 2 & 3 loop the insertion point is put into the correct cell and the hole cell is selected
2) on entering the For 1 to x loop the cell is merged with the correct number of cells to the right and the bottom border goes across just the merged cells
3) on looping to the next x the insertion point moves correctly to the next cell BUT instead of the border being applied to just the selected cell, all cells from the start of the row up to and including the selected cell are bordered.
4) HOWEVER! on looping to row 3 the code steps across the columns bordering and merging cells as I wish.
I can't see why the borders are failing first time through the outer loop but it all works as expected the second time through.
Ken
Code: Select all
.
.
somewhere before the loops the variable 'offset' gets a value, say = 1
.
.
For hdrRow = 2 To 3
Set rng = Selection.Tables(1).Cell(hdrRow, 3).Range
rng.Collapse Direction:=wdCollapseStart
rng.Select
startingColNum = 3
For analyteNo = 1 To num
Selection.Tables(1).Cell(hdrRow, startingColNum).Select
With Selection
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorBlack
End With
End With
With Selection.Tables(1)
Set rng = .Cell(hdrRow, startingColNum).Range
rng.End = .Cell(hdrRow, startingColNum + offset).Range.End
rng.Cells.Merge
End With
startingColNum = startingColNum + 2
Next analyteNo
Next hdrRow