changing font format via vb

asylum

Board Regular
Joined
Dec 2, 2003
Messages
243
Hi,

I have a sheet with lot of data in range a1: t100 all of it is text, there are no formulas in here.

Sprinkled throughout the data there are a couple of hundred instances of an exclamation mark !.

I need to turn all of these into bold format, they may appear anywhere in the text. I anticipate it being something like:

Sub bold()

Dim boldrng as range

set boldrange = (a1,t100)

for each cell in range find "!" and when found then:

With ActiveCell.Characters(!).Font
.FontStyle = "Bold"

End With

End Sub

any thoughts?

Thanks

Andy
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
Sub Bold()
Dim r As Range
Dim l As Integer

Application.ScreenUpdating = False

For Each r In Range("A1:T100")
    If InStr(1, r.Value, "!", 1) Then
        l = WorksheetFunction.Find("!", r.Value)
        r.Characters(Start:=l, Length:=1).Font.Bold = True
    End If
Next r

Application.ScreenUpdating = True

End Sub
 
Upvote 0
HI Neil,

Thats great thanks works a treat... but.... (i should have mentioned this), sometimes cell contain more than one !, such as

apples! oranges bananas!

and this only find an changes the first instance, how woudl we modify it to get all instances?

Thanks

Andy
 
Upvote 0
A bit messy, and may take a while if your cells contain hundreds of characters...

Code:
Sub Bold2()
Dim r As Range
Dim i As Integer

Application.ScreenUpdating = False

For Each r In Range("A1:T100")
    If InStr(1, r.Value, "!", 1) Then
        For i = 1 To Len(r.Value)
            If r.Characters(Start:=i, Length:=1).Text = "!" Then _
            r.Characters(Start:=i, Length:=1).Font.Bold = True
        Next i
    End If
Next r
            
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top