Word count from word 1 to the first occurance of a particular phrase in a cell

inosent

Board Regular
Joined
Mar 19, 2007
Messages
128
Let's say I have this text in a cell, and I want to count all the words from word 1 to the first occurance of the phrase "Thank you":

"The quick brown fox jumped over the fence to say Hello.

Thank you

The blue car was parked on the street and ..."

The result is 11.

This works great for an overall word count, =IF(LEN(TRIM(M2))=0,0,LEN(TRIM(M2))-LEN(SUBSTITUTE(M2," ",""))+1)

but I only need to count the first part of the text in the cell as noted above
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
5,146
Hi,

Try this:

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style=";">The quick brown fox jumped over the fence to say Hello.

Thank you

The blue car was parked on the street and …</td><td style="text-align: right;;">11</td></tr></tbody></table><p style="width:6.4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet625</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B1</th><td style="text-align:left">=LEN(<font color="Blue">TRIM(<font color="Red">REPLACE(<font color="Green">A1,SEARCH(<font color="Purple">"Thank you",A1</font>),LEN(<font color="Purple">A1</font>),""</font>)</font>)</font>)-LEN(<font color="Blue">SUBSTITUTE(<font color="Red">TRIM(<font color="Green">REPLACE(<font color="Purple">A1,SEARCH(<font color="Teal">"Thank you",A1</font>),LEN(<font color="Teal">A1</font>),""</font>)</font>)," ",""</font>)</font>)+1</td></tr></tbody></table></td></tr></table><br />
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
Try this too:

Excel Workbook
LMN
1
2The quick brown fox jumped over the fence to say Hello.Thank youThe blue car was parked on the street and 11
sheet1
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,236
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top