Conditional Formatting by character count

rjwell

New Member
Joined
Mar 30, 2009
Messages
5
If this topic is covered by a previous thread ... please forgive and link me to the thread.

I've been searching for code that can do the following ...

After cell update
If character count is 5 or less set font size equal to 12
If character count greater than 5 set font size equal to 10

I'm not into coding and any of my VBA attempts results in no change.

Thanks for the help.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Welcome, right click on the sheet tab you want the code to run in and select view code. Then paste this in...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Select Case Len(Target.Value)
    Case Is <= 5: Target.Font.Size = 12
    Case Else: Target.Font.Size = 10
End Select

End Sub

Hope this helps
 
Upvote 0
Thanks Georgiboy,

One problem (I think) I don't want it applied to every cell on the sheet, which your solution would do, right?

How can I apply that to just cell B43 (for example).

Thanks for your help.
 
Upvote 0
For a single cell you could use...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B43")) Is Nothing Then
    Select Case Len(Target.Value)
        Case Is <= 5: Target.Font.Size = 12
        Case Else: Target.Font.Size = 10
    End Select
    
End If
End Sub

For more than one single cell you could use...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B43, B45, B47")) Is Nothing Then
    Select Case Len(Target.Value)
        Case Is <= 5: Target.Font.Size = 12
        Case Else: Target.Font.Size = 10
    End Select
    
End If
End Sub

Hope this helps
 
Upvote 0
For a single cell you could use...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B43")) Is Nothing Then
    Select Case Len(Target.Value)
        Case Is <= 5: Target.Font.Size = 12
        Case Else: Target.Font.Size = 10
    End Select
    
End If
End Sub

For more than one single cell you could use...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("B43, B45, B47")) Is Nothing Then
    Select Case Len(Target.Value)
        Case Is <= 5: Target.Font.Size = 12
        Case Else: Target.Font.Size = 10
    End Select
    
End If
End Sub

Hope this helps
I was hoping you could help me out, I have a similar situation, only I want to apply a red background to any cell with more than 60 characters. And I need to apply this to an entire column (almost 10,000 rows of data).

If it has less than 60 characters it doesn't have to do anything. I've tried to do this through Conditional Formatting (there's another thread about using "=LEN($D4)>60") but it didn't work, some cells with only 23 characters got the red background, and some cells with 63 characters didn't get the red background. Any ideas?

Thank you so much!
 
Upvote 0
Hi. I can't replicate this.

I used
Code:
=LEN(D4)>60
and it seems to work fine.

Can you give an example of one of the text strings that gives you the wrong result ?
 
Upvote 0
the following two both had the red background:
C Welding Fabrication
D Hospitality and Tourism Management- Intern Travel and Tourism
and then right below the D Hospitality one was an idea course name that WASN'T red.

The Welding name shouldn't have turned red, and the second Hospitality program should have.
 
Upvote 0
Maybe try:

=LEN(trim(D4))>60

Also make sure there are no quotes in teh formula in conditional formatting.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

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