Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Restricting Number of characters in a cell


Hi All

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Restricting Number of characters in a cell

Assuming you want to keep whats on the left:
=LEFT(A2,25)

alternatively:
=RIGHT(A2,25)

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Colin Hayes" wrote:


Hi All

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default Restricting Number of characters in a cell

Colin Hayes wrote:

Hi All

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks



If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"…"))

Change the three 25's for a different length.
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default Restricting Number of characters in a cell

Glenn wrote:
Colin Hayes wrote:

Hi All

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks



If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"…"))

Change the three 25's for a different length.



A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"…"))
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default Restricting Number of characters in a cell

Glenn wrote:
Glenn wrote:
Colin Hayes wrote:

Hi All

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks



If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"…"))

Change the three 25's for a different length.



A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"…"))



And now there are four 25's to change.


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Restricting Number of characters in a cell

You say you want to "trim the contents of a cell"... does that mean you want
your users to enter something into a cell and then you want to automatically
have Excel truncate the entry down to 25 characters within the SAME cell
that the entry was made in? If this is what you meant, then you can't do it
with a formula (the user's entry would replace any formulas with such
cells)... it will take a macro to accomplish this... but you will need to
provide some more information. What cell or range of cells should this
functionality be restricted to? Will any of the cells in this range have
formulas in them? Will any of the cells in the range have numerical data in
them?

--
Rick (MVP - Excel)


"Colin Hayes" wrote in message
...

Hi All

I need to trim the contents of a cell to 25 characters. It doesn't matter
if some text gets chopped from the end of the content , providing it's no
longer than 25 characters.

Can someone kindly suggest a formula for this , please?


Thanks


  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Restricting Number of characters in a cell

I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?


If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"…"))

Change the three 25's for a different length.


A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"…"))


This slightly shorter formula (using two less function calls) appears to do
what your formula is doing...

=SUBSTITUTE(LEFT(A1,25)," "&TRIM(RIGHT(SUBSTITUTE
(TRIM(LEFT(A1,25))," ",REPT(" ",99)),99)),"")&"…"

I would note that just adding the ellipses to the end can produce a
resulting string that is longer than 25 character. Our formulas also differ
on how they handle text whose 25th character is a space character.

--
Rick (MVP - Excel)

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default Restricting Number of characters in a cell

Rick Rothstein wrote:
I need to trim the contents of a cell to 25 characters. It doesn't
matter if some text gets chopped from the end of the content ,
providing it's no longer than 25 characters.

Can someone kindly suggest a formula for this , please?

If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"…"))

Change the three 25's for a different length.


A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"…"))


This slightly shorter formula (using two less function calls) appears to
do what your formula is doing...

=SUBSTITUTE(LEFT(A1,25)," "&TRIM(RIGHT(SUBSTITUTE
(TRIM(LEFT(A1,25))," ",REPT(" ",99)),99)),"")&"…"



Only slightly shorter if you eliminate my first line, which checks for blanks
and contents that don't need adjustment. And I got some strange results with
this in A1:

123 56789 123 56789 123 56789 123 56789
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Restricting Number of characters in a cell


If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"€¦"))

Change the three 25's for a different length.



A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"€¦"))


Hi

OK thanks for this. It works fine and is very neat.

I do find the final three dots do actually make the line longer than the
limit set in the formula , which is a curious anomaly.


Best Wishes
  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,240
Default Restricting Number of characters in a cell

Colin Hayes wrote:

If you care where it gets chopped:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)),
LEN(SUBSTITUTE(LEFT(A1,25+1)," ",REPT(" ",99)))-99))&"€¦"))

Change the three 25's for a different length.



A little better:

=IF(A1="","",IF(LEN(A1)<=25,A1,
TRIM(LEFT(SUBSTITUTE(A1," ",REPT(" ",99),
25-LEN(SUBSTITUTE(LEFT(A1,25+1)," ",""))+1),25))&"€¦"))


Hi

OK thanks for this. It works fine and is very neat.

I do find the final three dots do actually make the line longer than the
limit set in the formula , which is a curious anomaly.


Best Wishes



You can just drop the &"..." if you want to keep it to a max of 25. I just
added that to give an indication that there was more to the original text.
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
Restricting Characters within a User Form DarnTootn Excel Discussion (Misc queries) 3 December 10th 08 10:45 PM
I need to have a certain number of characters in a cell jerminski73 Excel Discussion (Misc queries) 9 November 11th 08 11:07 AM
Keep specified number of characters at end of cell? Kevin Excel Worksheet Functions 1 July 20th 07 04:40 PM
restricting use of certain characters Rob Excel Discussion (Misc queries) 4 June 8th 06 01:07 AM
set the number of characters in a cell CF Excel Discussion (Misc queries) 4 February 9th 06 09:37 PM


All times are GMT +1. The time now is 07:37 AM.

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"