Macro to conditonally format cells >255 characters

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Does anybody know how I would code a macro to conditionally format any cell that is >255 characters? The conditional format could be anything but I think changing the cell colour/font colour to red would be the best option.

Here is a simple example of what I am after:

Apple (+255 more characters)BananaCherry
AsparagusBean (+255 more characters)Carrot
AguaBeerCoke (+255 more characters

<tbody>
</tbody>

Run macro:
Apple (+255 more characters)BananaCherry
AsparagusBean (+255 more characters)Carrot
AguaBeerCoke (+255 more characters

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Are you specifically looking for a macro, or will Conditional Formatting do? To use CF, try this:

1) Select the range you want to evaluate (for this example, A1 is the top left corner)
2) Click Conditional Formatting > New Rule > Use a formula > and enter:
=LEN(A1)>255
in the formula box.
3) Click Format... and select a fill color or font color.
4) Click OK.

Let me know if that works for you.
 
Upvote 0
Thanks Eric,

Yeah I was specifically looking for a macro unless you know of a better solution to my problem (explained in the next sentence). I have been copy/pasting information from one sheet into another and the condtional formatting seems to get overridden when I paste the information from one sheet to the next. I have tried protecting the sheet from formatting too with no success. I am probobly doing something wrong.

Ultimately this is what I am after:
  • Copy cells from Sheet1/Spreadsheet1 (no conditional formatting)

  • Paste cells from Sheet1 into Sheet2/Spreadsheet2 (empty sheet with conditional formatting)

  • Sheet2 condtional formatting does not get overridden
 
Upvote 0
Are you doing the Copy/Paste manually or by macro?
In either case, instead of Paste, can you use the following?
Paste Special -> Values
 
Upvote 0
Thanks Peter,

Problem solved. I had tried that originally but the cells do not automatically format in with colour until I changed out of the Sheet and then back into it for some reason? That is what messed me up.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,509
Members
449,089
Latest member
RandomExceller01

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