Sometimes it is desired to trim a sentence to a given length so that i can be accommodated into a a cell. Lets say we have a sentence but we want to restrict its length to 80 characters. A solution could be to use LEFT() function that will take Text & Text Length as arguments and will furnish a 80 character long Text String but what if the 80th character ends up in middle of a word? Lets understand it with an example, take the following sentence:
"MY NAME IF FASEEH AND I AM LEAVING FOR TEXAS. I WILL BE TRAVELING BY A LOCAL TRAIN THAT WILL TAKE 08 HRS TO REACH BOSTON."
This sentence has 121 characters including spaces. If i use LEFT() to find the first 80 characters, it will return following text:
"MY NAME IF FASEEH AND I AM LEAVING FOR TEXAS. I WILL BE TRAVELING BY A LOCAL TRA"
You see that the sentence does ends "naturally" rather it is terminated in middle of a word. The ideal solution would have been either to include the complete word "TRAIN" or stop before the word starts. In case we want to stop before the word "TRAIN" started (that should be the case because we restricted to limit of 80 characters) the length of the sentence would have been 76 characters instated of 80. (The " TR" portion being excluded}.
The following formula assured that "Word at the end of the sentence is not got chewed up by our formula"
=IF(LEN(A2)<=80,A2,LEFT(A2,MATCH(80,IF(MID(A2,ROW($A$1:$A$250),1)=" ",ROW($A$1:$A$250)))-1))
Here is the Sample Workbook
This is a repository to the work I do on Excel, $LaTeX$ and any other interesting thing I came across.
Subscribe to:
Post Comments (Atom)
The Google Sheet Assignment - Splitting and Transposing Cell based on Delimiter - Part 1
I recently had opportunity to workout a formula with google sheets, where i realized how powerful google sheet formulas are. The problem ...
-
PLOTTING THE BASIC CURVE: Since there is no specific equation available to plot the chart therefore I tried to create it in two p...
-
In this post I will be explaining how to run the Simple Linear Regression (Ordinary Least Square) to create the model using Eviews 7.0. Evi...
-
My today’s post is about Survival Analysis with Kaplan-Meier Method. This post uses an example for a popular multivariate analysis tex...
No comments:
Post a Comment