Bolding from 1st character up to :

seekyourway

New Member
Joined
Nov 1, 2011
Messages
21
Hi,

I wanted to bold all the characters in a range from the beginning up to where the ":" is. Sample files:

dsjakgjdkfa: dgda. (50%)
geadfdafd: fdagad, (.)
gadfdgad: gdadg @gdad

Data is always in 1st column. I have some code below, but when I run it, it bolds the whole thing, bypassing what's in the loop. Would someone please give an advice/pointer?

Sub Bolder2()
Dim rng As Range, r As Range, strR As String
Dim i As Long, j As Long, k As Long
Set rng = Intersect(Columns(1), ActiveSheet.UsedRange)
For Each r In rng
strR = r.Text

For i = 1 To InStr(strR, ":")
r.Font.Bold = True
Next i
Next r
End Sub

Thank you for your assistance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
This will work to do that. You need to ensure that only the characters are being emboldened, which requires your code to specify Characters within the Cell only:
VBA Code:
Sub colourUpToColonColumnA()
    Dim lngLoop As Long
    Dim lngLastRow As Long
    Dim intPos As Integer
    lngLastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
    For lngLoop = 1 To lngLastRow
        intPos = InStr(Cells(lngLoop, 1), ":")
        If intPos > 0 Then
            Cells(lngLoop, 1).Characters(Start:=1, Length:=intPos).Font.Bold = True
        End If
    Next lngLoop
End Sub

Or using your code as a base:
VBA Code:
Sub Bolder2()
    Dim rng As Range, r As Range, strR As String
    Dim i As Long, j As Long, k As Long
    Set rng = Intersect(Columns(1), ActiveSheet.UsedRange)
    For Each r In rng
    strR = r.Text
        For i = 1 To InStr(strR, ":")
            r.Characters(Start:=1, Length:=i).Font.Bold = True
        Next i
    Next r
End Sub

PS: You should also ensure your profile shows what version(s) and platform(s) you are using otherwise posters may waste their time and work on solutions that you are unable to use.
 
Last edited:
Upvote 0
S: You should also ensure your profile shows what version(s) and platform(s) you are using otherwise posters may waste their time and work on solutions that you are unable to use.
I agree.

FWIW, the default starting position for 'Characters' is 1 so this would be sufficient in either code
Rich (BB code):
_ _.Characters(Length:=i).Font.Bold = True
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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