That bit you were doing fine except for a couple of missing End With's. The
only thing I would add there is a check on the length of the first two cell
references as this will affect which characters you need to format:
Private Sub Worksheet_Calculate()
On Error GoTo ErrorHandler
Application.EnableEvents = False
Dim LCRate As Integer
Dim LActA As Integer
Range("A5").Value = "Usage Instruction: Vary contribution rate " _
& Application.WorksheetFunction. _
Substitute(Range("ContRate").Address, "$", "") _
& " in order to set Actual Annuity " _
& Application.WorksheetFunction. _
Substitute(Range("ActAn").Address, "$", "") _
& " to the value of the Required Annuity " _
& Application.WorksheetFunction. _
Substitute(Range("ReqAn").Address, "$", "") _
& " by pressing the button above."
LCRate = Len(Application.WorksheetFunction. _
Substitute(Range("ContRate").Address, "$", ""))
LActA = Len(Application.WorksheetFunction. _
Substitute(Range("ActAn").Address, "$", ""))
' The following code changes the style of the words CONTRIBUTION RATE
'in the first phrase in A5 to bold and green
With Range("A5").Characters(Start:=25, Length:=17).Font
.FontStyle = "Bold"
.ColorIndex = 50
End With
' The following code attempts to change the style of the words ACTUAL
'ANNUITY in the second phrase in A5 to bold and green
With Range("A5").Characters(Start:=60 + LCRate, Length:=14).Font
.FontStyle = "Bold"
.ColorIndex = 50
End With
' The following code attempts to change the style of the words REQUIRED
'ANNUITY in the third phrase in A5 to bold and green
With Range("A5").Characters(Start:=96 + LCRate + LActA, Length:=16).Font
.FontStyle = "Bold"
.ColorIndex = 50
End With
ErrorHandler:
Application.EnableEvents = True
End Sub
Regards
Rowan
"gvm" wrote:
That helps Rowan thanks, but now how do I change the font style of the terms
"contribution rate", "actual annuity" and "required annuity" in the various
character strings to bold and green?
|