Highlight cells whose word count exceeds a given limit

BlackieHamel

Board Regular
Joined
May 9, 2014
Messages
93
I have a questionnaire being filled out by 10 respondents, and I want to limit the word count of the replies. Through some googling, I've found this formula for counting the words in a cell:
Code:
=IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ",""))+1)

What I would like to do, on each of 70 rows of a spreadsheet, is to specify in Column A the max word count, and then use conditional formatting to highlight any cell whose count exceeds that limit. My first problem is to get rid of those three "A2" references, since I want to reference the current cell -- and I'm not sure how to do that.

Can you help? Thanks.

Blackie
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Like this? Select B2 to the bottom right of your data and apply the CF formula shown.

Excel Workbook
ABCD
23one two threecat dog horse mouse
35red blue green yellow pink orange blackblue
41housebrick
54chairtablechair table plate knife fork spoon
Limit words
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B21. / Formula is =LEN(B2)-LEN(SUBSTITUTE(B2," ",""))>$A2-1Abc
 
Upvote 0
Try

=((LEN(TRIM(B2))-LEN(SUBSTITUTE(B2," ",""))+1)-$A2)<0)
or
=ISNUMBER(SEARCH("|",SUBSTITUTE(TRIM(B2)," ","|",A2)))

You don't need to get rid of the references, you need them there. The reference is relative, so it always refers to the current cell.

If you want to apply the conditional formatting to C10:Z50 then change B2 to C10 (the top left cell of the range to be formatted) and $A2 to the cell that specifies the word count for that row.
 
Upvote 0
Thanks, Peter! That works like a charm.

May I piggyback a question? I have a filled-in worksheet with sample answers for each row, and I'd like to calculate the average number of words in the cells of that row (this will be to come up with the limitations to go in Column A). What would that formula be?
 
Upvote 0
Assuming that your cells to average are A1:Z1, try
=AVERAGE(INDEX(LEN(A1:Z1)-LEN(SUBSTITUTE(A1:Z1," ",""))+1,))
Note that I haven't allowed for any of the cells being empty.
 
Upvote 0
Thanks, Peter! That works like a charm.
You're welcome. :)


May I piggyback a question? I have a filled-in worksheet with sample answers for each row, and I'd like to calculate the average number of words in the cells of that row (this will be to come up with the limitations to go in Column A). What would that formula be?
Clever answer by jasonb75. (y)
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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