Format Cell based on # of characters...

tdfsu

New Member
Joined
Mar 20, 2009
Messages
10
I want to change the background color of a cell if the number of characters is 255 or above. But I do not have room to add cells to count using LEN. I have a large range of cells, of which, all have a lot of text typed in.

I'd like to do it as a subroutine. I found this code, but I cannot get it to work.


Sub myAddColor()
' Add color if Range("A1:D100") greater than 255, if 255 remove color.
' By Joe Was
'
Range("A1:D100").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="255"
Selection.FormatConditions(1).Interior.ColorIndex = 8
Range("A1").Select
End Sub



I'd greatly appreciate any help,
Jason.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Does this do what you want?

Sub myAddColor2()
Range("A1:D100").Select
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=LEN(A1)>255"
.FormatConditions(1).Interior.ColorIndex = 8
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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