Sunday, 30 December 2012

Formatting all specific text into bold / removing bold



'Convert all specified text on Worksheet into bold font
Sub BoldFont()
    Dim rNa As Range
    Dim FindIt As String
    Dim strAddy As String
    'Application box so the specific word is entered and searched for
    Prompt = "What is the value you want to apply the bold font to?"
    Title = "Search Value Input"
    FindIt = InputBox(Prompt, Title)
    Set rNa = ActiveSheet.UsedRange.Find(What:=FindIt, LookIn:=xlValues, LookAt:=xlWhole, _
                                         SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

    If Not rNa Is Nothing Then
        strAddy = rNa.Address
        Do
            'make the specific word bold
            rNa.Font.Bold = True
            ' add any other formatting required here
            Set rNa = ActiveSheet.UsedRange.FindNext(rNa)
        Loop While rNa.Address <> strAddy
    End If
End Sub

'Convert all specified text on Worksheet into non-bold font
Sub RemoveBoldFont()
    Dim rNa As Range
    Dim FindIt As String
    Dim strAddy As String
    'Application box so the specific word is entered and searched for
    Prompt = "What is the value you want to remove the bold font from?"
    Title = "Search Value Input"
    FindIt = InputBox(Prompt, Title)
    Set rNa = ActiveSheet.UsedRange.Find(What:=FindIt, LookIn:=xlValues, LookAt:=xlWhole, _
                                         SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

    If Not rNa Is Nothing Then
        strAddy = rNa.Address
        Do
            'make the specific word bold
            rNa.Font.Bold = False
            ' add any other formatting required here
            Set rNa = ActiveSheet.UsedRange.FindNext(rNa)
        Loop While rNa.Address <> strAddy
    End If
End Sub

No comments:

Post a Comment