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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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