Bolding Subtotals
I just realized I did not put a MsgBox to cancel the operation if no
subtotals were found. I tried putting an Else statement under the actions to
take if the condition was met with a MsgBox to display and the command Exit
Sub below the MsgBox, and it gave me the error "No cells were found." I gave
this macro to someone else, and I want to know where to put the MsgBox to
cancel the operation without the other person freaking out. Other than that,
the code you gave me works. Here's what I did:
Sub SubtotalBold
Dim myC As Range
For Each myC In Cells.SpecialCells(xlCellTypeFormulas, 23)
If InStr(1, myC.Formula, "SUBTOTAL") 0 Then
myC.Font.Bold = True
Else
MsgBox [Msg]
Exit Sub
End If
Next myC
End Sub
--
Please rate posts so we know when we have answered your questions. Thanks.
"Bernie Deitrick" wrote:
Onion,
You would want to search the formula string, not the text
Sub Macro1()
Dim myC As Range
For Each myC In Cells.SpecialCells(xlCellTypeFormulas, 23)
If InStr(1, myC.Formula, "SUBTOTAL") 0 Then
myC.Font.Bold = True
End If
Next myC
End Sub
HTH,
Bernie
MS Excel MVP
"Orion Cochrane" wrote in message
...
Excel 2003:
I was wondering if there is a way to write a macro that would bold any
subtotal on a worksheet. What I was thinking of doing is have some sort of
Do/Loop macro with a LEFT function where if Left(ActiveCell.Text, 9) =
"=SUBTOTAL" then bold the cell. It would then search all cells in the
worksheet with that condition and would look until, say, the activerow is
blank (or a better cutoff if you can think of one). I work with a lot of
reports and there are some who would like to use this macro, and I am the
only one who would know how to run it and where to install it to make it
available to others. Thanks.
--
Please rate posts so we know when we have answered your questions. Thanks.
|