Page 205 - Excel Progamming Weekend Crash Course
P. 205
k540629 ch14.qxd 9/2/03 9:34 AM Page 180
180 Saturday Afternoon
Listing 14-1 Continued
‘ - Thick border below the top row.
‘ - Thick border to the right of the left column.
‘ - Thin horizontal borders between other cells.
‘ - Top row text in boldface and centered horizontally.
‘ - Left column text in boldface and right-aligned.
Dim r As Range, r1 As Range
‘ Make sure the selection is a region.
If TypeName(Selection) <> “Range” Then
MsgBox “A worksheet cell must be active to run this program.”
Exit Sub
End If
‘ Get a region for the entire table.
Set r = Selection.CurrentRegion
‘ Put thin horizontal borders inside the region.
r.Borders(xlInsideHorizontal).LineStyle = xlContinuous
r.Borders(xlInsideHorizontal).Weight = xlThin
‘ Get the top row of the region
Set r1 = r.Rows(1)
‘Put a thick border at the bottom of the row.
r1.Borders(xlEdgeBottom).LineStyle = xlContinuous
r1.Borders(xlEdgeBottom).Weight = xlThick
‘ Make text in the row bold and centered.
r1.Font.Bold = True
r1.HorizontalAlignment = xlCenter
‘ Get the left column of the region.
Set r1 = r.Columns(1)
‘ Put a thick border at the right edge of the column.
r1.Borders(xlEdgeRight).LineStyle = xlContinuous
r1.Borders(xlEdgeRight).Weight = xlThick
‘ Make text in the column bold and right-aligned.
r1.Font.Bold = True
r1.HorizontalAlignment = xlRight
End Sub