Zsolt Hidvegi
Zsolt Hidvegi

Reputation: 1

VBA excell, change format of one word within a cell

I have a issue to change all bold text withing a couple of cells to ALLCAPS (or even to a different alcaps font)

I saw a couple of similar modules but I am not an expert to change the condition and the loop.

(so change all words from bold to allcaps withing a selection - no full cells)

Upvotes: 0

Views: 41

Answers (1)

kamikadze366
kamikadze366

Reputation: 156

try this one, works pretty well for me. Below code changes every bold letter into uppercase:

Sub BoldToUpper()
    
    Dim i As Integer
    Dim cell As Variant
    
    For Each cell In Selection
    
        'Check each character of a string
        For i = 1 To Len(cell.Value)
            With cell.Characters(i, 1)
               'Possible adjustment due to regional settings
                If .Font.FontStyle = "Bold" Or .Font.FontStyle = "Bold Italic" Then
                    .Caption = UCase(.Caption)
                    'Possible adjustment due to regional settings
                    .Font.FontStyle = "Regular" 'Deletes bold effect
                End If
            End With
        Next i

    Next cell
    
End Sub

enter image description here

Note, that perhaps you may adjust the code to your local language settings.

For example in polish:

If .Font.FontStyle = "Pogrubiony" Or .Font.FontStyle = "Pogrubiona kursywa" Then

Upvotes: 1

Related Questions