Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Truncating a cell entry to the last full word

Hi All,

I've searched in this amazing forum and found a forumla to truncate a
cell length: (assuming data is in A2)
=IF(LEN(A2)399,LEFT(A2,399),A2 & REPT(" ",399-LEN(A2)))

I'm trimming down text entries in a large spreadsheet where the
maximum number of characters in a cell has to be under 400.

Just wondering if anybody has any handy tips on truncating the cell as
above, but also cutting it off at the last whole word.

One thought I had was a formula that does the following: (assuming
text data of 399 characters is in A1)
"If last character in A1 is not a blank (space), then delete last
character in A1"

That would eliminate the last character of cell A1 that doesn't end in
a blank (space).

Thereafter it would just be a case of reapplying the formula a few
times until all the characters of a truncated word have been deleted
and the cell ends with a blank (space) and that would mean that the
cell is under 399 characters in length and ends with a blank (space) =
truncation to the last full word.

Does that sound feasible? No need for a macro that repeats the formula
until the cell ends with a blank (space), I can repeat the forumla
manually to have the desired effect.

I would greatly apprecaite any help on this at all,

Thanks in advance,

All the best,

Pat
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default Truncating a cell entry to the last full word

Do you want the function to return the last word in a sentence or the
sentence with the last word removed?
--
Gary''s Student - gsnu2007d


"Pat" wrote:

Hi All,

I've searched in this amazing forum and found a forumla to truncate a
cell length: (assuming data is in A2)
=IF(LEN(A2)399,LEFT(A2,399),A2 & REPT(" ",399-LEN(A2)))

I'm trimming down text entries in a large spreadsheet where the
maximum number of characters in a cell has to be under 400.

Just wondering if anybody has any handy tips on truncating the cell as
above, but also cutting it off at the last whole word.

One thought I had was a formula that does the following: (assuming
text data of 399 characters is in A1)
"If last character in A1 is not a blank (space), then delete last
character in A1"

That would eliminate the last character of cell A1 that doesn't end in
a blank (space).

Thereafter it would just be a case of reapplying the formula a few
times until all the characters of a truncated word have been deleted
and the cell ends with a blank (space) and that would mean that the
cell is under 399 characters in length and ends with a blank (space) =
truncation to the last full word.

Does that sound feasible? No need for a macro that repeats the formula
until the cell ends with a blank (space), I can repeat the forumla
manually to have the desired effect.

I would greatly apprecaite any help on this at all,

Thanks in advance,

All the best,

Pat

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Truncating a cell entry to the last full word

Hi Pat,

this formula will find the position of the last space up to 399
characters from a string in A2:

=FIND(CHAR(1),SUBSTITUTE(LEFT(A2,399)," ",CHAR(1),(399-
LEN(SUBSTITUTE(LEFT(A2,399)," ","")))))

so, if you have such a long string, then this will return only
complete words up to but excluding that last space:

=LEFT(A2,FIND(CHAR(1),SUBSTITUTE(LEFT(A2,399)," ",CHAR(1),(399-
LEN(SUBSTITUTE(LEFT(A2,399)," ","")))))-1)

This more-complete formula will return either the complete text if it
is less than 399 characters, or text truncated to the last complete
word so that it is less than 400 characters:

=IF(LEN(A2)399,LEFT(A2,FIND(CHAR(1),SUBSTITUTE(LE FT(A2,399),"
",CHAR(1),(399-LEN(SUBSTITUTE(LEFT(A2,399)," ","")))))-1),A2)

You could then apply your formula in to add trailing spaces to the end
of this result in a separate cell, or you could combine that, as
follows:

=LEFT(IF(LEN(A2)399,LEFT(A2,FIND(CHAR(1),SUBSTITU TE(LEFT(A2,399),"
",CHAR(1),(399-LEN(SUBSTITUTE(LEFT(A2,399)," ","")))))-1),A2)&REPT(" ",
399),399)

i.e. add on loads of spaces then just take the first 399 characters.

Hope this helps.

Pete


On Feb 21, 2:12*pm, Pat wrote:
Hi All,

I've searched in this amazing forum and found a forumla to truncate a
cell length: (assuming data is in A2)
=IF(LEN(A2)399,LEFT(A2,399),A2 & REPT(" ",399-LEN(A2)))

I'm trimming down text entries in a large spreadsheet where the
maximum number of characters in a cell has to be under 400.

Just wondering if anybody has any handy tips on truncating the cell as
above, but also cutting it off at the last whole word.

One thought I had was a formula that does the following: (assuming
text data of 399 characters is in A1)
"If last character in A1 is not a blank (space), then delete last
character in A1"

That would eliminate the last character of cell A1 that doesn't end in
a blank (space).

Thereafter it would just be a case of reapplying the formula a few
times until all the characters of a truncated word have been deleted
and the cell ends with a blank (space) and that would mean that the
cell is under 399 characters in length and ends with a blank (space) =
truncation to the last full word.

Does that sound feasible? No need for a macro that repeats the formula
until the cell ends with a blank (space), I can repeat the forumla
manually to have the desired effect.

I would greatly apprecaite any help on this at all,

Thanks in advance,

All the best,

Pat


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Truncating a cell entry to the last full word

Hi Pete,

That's fabulous stuff. How many maths A-Levels did you do? ;-)

Thanks a million,

Cheers,

Pat
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Truncating a cell entry to the last full word

You're welcome, Pat. Glad it worked for you.

I did my A levels when they were proper qualifications, so they are
probably worth several times today's offerings !! <bg

Pete

On Feb 21, 3:42*pm, Pat wrote:
Hi Pete,

That's fabulous stuff. How many maths A-Levels did you do? ;-)

Thanks a million,

Cheers,

Pat


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting abbreviated days, converting to full word Sneilan Excel Discussion (Misc queries) 4 October 19th 07 04:02 PM
Truncating whole numbers - diplaying thousands instead of full num Reez Excel Discussion (Misc queries) 1 May 7th 07 04:29 PM
truncating data within a cell for an entire column vlapi New Users to Excel 3 April 18th 07 08:15 PM
in one sheet add one word after every entry in every cell. how? Sandy Excel Worksheet Functions 3 December 20th 06 07:04 PM
Link cell is truncating text Mikeice Excel Worksheet Functions 0 August 9th 05 11:58 AM


All times are GMT +1. The time now is 03:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"