Conditional Format part of a text string

lydytunes

New Member
Joined
Mar 16, 2011
Messages
38
Have done some research on line and on the board but can't find what I'm looking for. From what I've read I'm going to need VBA to do this but haven't been able to figure it out. I have a column that is going to be populated with up to a 40 character text string. I'm wanting to see if there is a way to make bold / change font / or highlight the first 24 characters of that text string. The values in the column will be different for each cell but they will never be over 40 characters and I will always want to highlight the first 24.

Again, I think this has to be done through VBA but haven't been able to find anything specific.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Use your mouse to select the cells in your column with the text strings you want to modify, then run the code below. In this case the first 24 characters will be seen in bold, red font.
Code:
Sub First24()
'select the cells you want to modify first, then run this macro
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection
    If c.Value <> "" Then
        c.Value = Trim(c.Value)
        With c.Characters(1, 24).Font
            .Bold = True
            .Color = vbRed
        End With
    End If
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This will change the font colour for the 1st 24 characters in col A
Code:
Sub Hilite()
Dim cl As Range
For Each cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
   cl.Characters(1, 24).Font.Color = 4567
Next cl
End Sub
 
Upvote 0
Joe and Fluff,

Thank you both for the quick response. I've tried them both and both worked. Glad I will have options depending on what my users want to do.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,959
Latest member
camelliaCase

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