techturtle
New Member
- Joined
- Mar 23, 2011
- Messages
- 5
I have a subroutine (Excel 2010) that includes subtotaling the data on a worksheet, then collapsing the subtotals. With the subtotal on level 2, I am trying to bold all the subtotaled numbers and apply a back color, while leaving the cells in between unbolded and white background. The code that I'm using is this:
The first selection and With block works as expected; it undoes all bolding and turns everything white. The second With block starts with the same selection, then uses the .SpecialCells(xlCellTypeVisible).select to change it so only the subtotaled rows are selected. In addition to seeing a visible change in the selection, I have verified via selection.cells.count that only those cells are in the selection. However, when the .Font.Bold and .Interior.Color sections execute, they hit everything, not just visible or selected cells. Any idea why this is happening?
Code:
Range(Cells(2, 1), Cells(lngLastRow, lngLastCol)).Select
With Selection
.Font.Bold = False
.Interior.Color = vbWhite
End With
With Selection
.SpecialCells(xlCellTypeVisible).Select
.Font.Bold = True
.Interior.Color = vbLtBlue
End With