Display a string from another cell, cutting off any word fragments Unicorn Meta Zoo #1: Why...
Prove the alternating sum of a decreasing sequence converging to 0 is Cauchy.
Does Feeblemind produce an ongoing magical effect that can be dispelled?
The art of proof summarizing. Are there known rules, or is it a purely common sense matter?
Rolling Stones Sway guitar solo chord function
What do you call the part of a novel that is not dialog?
"Rubric" as meaning "signature" or "personal mark" -- is this accepted usage?
Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?
Why did C use the -> operator instead of reusing the . operator?
Map material from china not allowed to leave the country
Why does the Cisco show run command not show the full version, while the show version command does?
Why did Israel vote against lifting the American embargo on Cuba?
Has a Nobel Peace laureate ever been accused of war crimes?
What is the least dense liquid under normal conditions?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
How to get even lighting when using flash for group photos near wall?
Seek and ye shall find
Are all CP/M-80 implementations binary compatible?
How would I use different systems of magic when they are capable of the same effects?
Can I criticise the more senior developers around me for not writing clean code?
What is the best way to deal with NPC-NPC combat?
How would this chord from "Rocket Man" be analyzed?
c++ diamond problem - How to call base method only once
Putting Ant-Man on house arrest
What ability score does a Hexblade's Pact Weapon use for attack and damage when wielded by another character?
Display a string from another cell, cutting off any word fragments
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraHow can I count unique comma-separated values in Excel 2010Excel formula to split a cell and reverses the orderCheck if a cell contains any of words from a dynamic listExtract number from complex string if it falls in a given rangeExcel, count characters except a stringEXCEL: Need formula that returns last time a value was >= current valueHow to ask excel to do sequenced formulas in single cellFind the part of the string that distinguishes a string in one cell from a string in another cellHow can I count how much wood a woodchuck chucks using Microsoft Excel?Subtracting values from a given cell, if those values are on a row with another cell with matching criteria
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm using this simple formula.
=LEN(A1,20)
But I want it to be able to cut off at the last space in the fragment so there aren't any incomplete words. How can I do this?
Here is an image of the current and desired result.
microsoft-excel worksheet-function spreadsheet
New contributor
add a comment |
I'm using this simple formula.
=LEN(A1,20)
But I want it to be able to cut off at the last space in the fragment so there aren't any incomplete words. How can I do this?
Here is an image of the current and desired result.
microsoft-excel worksheet-function spreadsheet
New contributor
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
1
I am not sure whether I understand you correctly. You writeLEN
here in your post, but you useLEFT
in your screenshot. I guess it has to be the latter, becaueLEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?
– padawan_IT
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago
add a comment |
I'm using this simple formula.
=LEN(A1,20)
But I want it to be able to cut off at the last space in the fragment so there aren't any incomplete words. How can I do this?
Here is an image of the current and desired result.
microsoft-excel worksheet-function spreadsheet
New contributor
I'm using this simple formula.
=LEN(A1,20)
But I want it to be able to cut off at the last space in the fragment so there aren't any incomplete words. How can I do this?
Here is an image of the current and desired result.
microsoft-excel worksheet-function spreadsheet
microsoft-excel worksheet-function spreadsheet
New contributor
New contributor
New contributor
asked 16 hours ago
Kevin R BreenKevin R Breen
1
1
New contributor
New contributor
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
1
I am not sure whether I understand you correctly. You writeLEN
here in your post, but you useLEFT
in your screenshot. I guess it has to be the latter, becaueLEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?
– padawan_IT
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago
add a comment |
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
1
I am not sure whether I understand you correctly. You writeLEN
here in your post, but you useLEFT
in your screenshot. I guess it has to be the latter, becaueLEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?
– padawan_IT
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
1
1
I am not sure whether I understand you correctly. You write
LEN
here in your post, but you use LEFT
in your screenshot. I guess it has to be the latter, becaue LEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?– padawan_IT
16 hours ago
I am not sure whether I understand you correctly. You write
LEN
here in your post, but you use LEFT
in your screenshot. I guess it has to be the latter, becaue LEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?– padawan_IT
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago
add a comment |
2 Answers
2
active
oldest
votes
I think this is what you are looking for :
English (not tested) :
=LEFT(A1,21-SEARCH(" ",SUBSTITUTE(RIGHT(A1,21)," "," ",21-LEN(SUBSTITUTE(RIGHT(A1,21)," ","")))))
French (tested) :
=GAUCHE(A1;21-CHERCHE(" ";SUBSTITUE(DROITE(A1;21);" ";" ";21-NBCAR(SUBSTITUE(DROITE(A1;21);" ";"")))))
Adapted from : https://forum.excel-pratique.com/viewtopic.php?t=3120
New contributor
add a comment |
There is nothing, really, one can do with formulas that will check the last "word" (string of letters) is a full word. Even if you loaded a monster dictionary to spellcheck against (formula methodology would be loading it in a way that a function such as SEARCH() or VLOOKUP() can search it), there could easily be valid words not contained in it.
One could check the final "word" for things like numerals or punctuation, but then there's the whole "Even though I say "word", what qualifies that is not really a word?" problem. For instance, would an email address be a valid word? Would it only be if it were complete? How about a hashtag word or phrase? How would one even know that is complete or check its spelling since a hashtag word might be "#ijyrrbt8"?
Alright, that aside, my approach would be to first check the last character of a 21 (not 20) character string. If it were a space, or any valid punctuation for the language in question, then I'd consider anything preceding it to be complete and therefore a valid word. Do so using an IF() test on a simple OR() clause. The OR() clause would be simple, though perhaps very long, depending upon all the ways a language might continue, especially with punctuation, after a valid word. Sadly, punctuation occurs INSIDE words too as a marker, for instance, of a contraction taking place: "don't" being an example in English.
After determining that, you are either done (say a space follows, I would consider the preceding "word" to be a valid word... except as noted at the end...), or not done. If not done, one moves on to reducing the 20 character string by stripping the offending end string in it. There is a "trick" used to make FIND() work here (it needs an instance number of what you seek to look for and won't take something like "last", sadly). One uses SUBSTITUTE() to eliminate all the spaces from the cell, or string in this case, taking the LEN() of the result (subtracting it from the LEN() of the original, but you know that is 20, so... well, except you don't (see just after the example formula) so take a LEN() of the string). The result is how many of the searched for characters are present in the string. Let's say the calculation result is 4 when searching for spaces. Therefore, there are four "spaces" in the 20 character string and you can use find to locate the last one:
=FIND( " ", 4 )
Caveat: since the string COULD have a space itself as character 20, wrap the LEFT() with TRIM(): TRIM(LEFT("20 character string being examined")) to drop any last space. Good thing you took a LEN() for the TRIM()-wrapped string, eh?
OK, So you have a value now that is 1 higher than you need so subtract 1 from it and use the result as the length to specify in a LEFT() function (instead of 20):
=TRIM( LEFT( "source string", "length found above" ))
2nd caveat: Does a string ending in "Mr." satisfy? Or would one, on reflection, like such things also removed? If not, awesome, much easier. If so, and it would be a perfectly valid way to think, if one saw such as always needing the name following, and therefore it is not a valid "word" since it is missing a portion of the slightly more broadly conceived definition of "word" -- one often finds even simple things like "word" can go sideways on one. I won't even try to demonstrate anything to deal with all the weirdness that could occur here except to offer that one could, upon finding such, have another searching clause subtract 1 from the earlier searching result and so finding the next to last space rather than the last... etc.
Then apply it to a reasonably large data set and look for failures due to rare or infrequent things you did not think of being present in your source data...
Sorry to seem cynical there, but we all know the nature of a beast like this. It's definitely live and learn! Keep adding to the OR() clause and making other adjustments to help clean the data for the actual final test.
New contributor
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Kevin R Breen is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1429092%2fdisplay-a-string-from-another-cell-cutting-off-any-word-fragments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this is what you are looking for :
English (not tested) :
=LEFT(A1,21-SEARCH(" ",SUBSTITUTE(RIGHT(A1,21)," "," ",21-LEN(SUBSTITUTE(RIGHT(A1,21)," ","")))))
French (tested) :
=GAUCHE(A1;21-CHERCHE(" ";SUBSTITUE(DROITE(A1;21);" ";" ";21-NBCAR(SUBSTITUE(DROITE(A1;21);" ";"")))))
Adapted from : https://forum.excel-pratique.com/viewtopic.php?t=3120
New contributor
add a comment |
I think this is what you are looking for :
English (not tested) :
=LEFT(A1,21-SEARCH(" ",SUBSTITUTE(RIGHT(A1,21)," "," ",21-LEN(SUBSTITUTE(RIGHT(A1,21)," ","")))))
French (tested) :
=GAUCHE(A1;21-CHERCHE(" ";SUBSTITUE(DROITE(A1;21);" ";" ";21-NBCAR(SUBSTITUE(DROITE(A1;21);" ";"")))))
Adapted from : https://forum.excel-pratique.com/viewtopic.php?t=3120
New contributor
add a comment |
I think this is what you are looking for :
English (not tested) :
=LEFT(A1,21-SEARCH(" ",SUBSTITUTE(RIGHT(A1,21)," "," ",21-LEN(SUBSTITUTE(RIGHT(A1,21)," ","")))))
French (tested) :
=GAUCHE(A1;21-CHERCHE(" ";SUBSTITUE(DROITE(A1;21);" ";" ";21-NBCAR(SUBSTITUE(DROITE(A1;21);" ";"")))))
Adapted from : https://forum.excel-pratique.com/viewtopic.php?t=3120
New contributor
I think this is what you are looking for :
English (not tested) :
=LEFT(A1,21-SEARCH(" ",SUBSTITUTE(RIGHT(A1,21)," "," ",21-LEN(SUBSTITUTE(RIGHT(A1,21)," ","")))))
French (tested) :
=GAUCHE(A1;21-CHERCHE(" ";SUBSTITUE(DROITE(A1;21);" ";" ";21-NBCAR(SUBSTITUE(DROITE(A1;21);" ";"")))))
Adapted from : https://forum.excel-pratique.com/viewtopic.php?t=3120
New contributor
New contributor
answered 9 hours ago
ClementAClementA
112
112
New contributor
New contributor
add a comment |
add a comment |
There is nothing, really, one can do with formulas that will check the last "word" (string of letters) is a full word. Even if you loaded a monster dictionary to spellcheck against (formula methodology would be loading it in a way that a function such as SEARCH() or VLOOKUP() can search it), there could easily be valid words not contained in it.
One could check the final "word" for things like numerals or punctuation, but then there's the whole "Even though I say "word", what qualifies that is not really a word?" problem. For instance, would an email address be a valid word? Would it only be if it were complete? How about a hashtag word or phrase? How would one even know that is complete or check its spelling since a hashtag word might be "#ijyrrbt8"?
Alright, that aside, my approach would be to first check the last character of a 21 (not 20) character string. If it were a space, or any valid punctuation for the language in question, then I'd consider anything preceding it to be complete and therefore a valid word. Do so using an IF() test on a simple OR() clause. The OR() clause would be simple, though perhaps very long, depending upon all the ways a language might continue, especially with punctuation, after a valid word. Sadly, punctuation occurs INSIDE words too as a marker, for instance, of a contraction taking place: "don't" being an example in English.
After determining that, you are either done (say a space follows, I would consider the preceding "word" to be a valid word... except as noted at the end...), or not done. If not done, one moves on to reducing the 20 character string by stripping the offending end string in it. There is a "trick" used to make FIND() work here (it needs an instance number of what you seek to look for and won't take something like "last", sadly). One uses SUBSTITUTE() to eliminate all the spaces from the cell, or string in this case, taking the LEN() of the result (subtracting it from the LEN() of the original, but you know that is 20, so... well, except you don't (see just after the example formula) so take a LEN() of the string). The result is how many of the searched for characters are present in the string. Let's say the calculation result is 4 when searching for spaces. Therefore, there are four "spaces" in the 20 character string and you can use find to locate the last one:
=FIND( " ", 4 )
Caveat: since the string COULD have a space itself as character 20, wrap the LEFT() with TRIM(): TRIM(LEFT("20 character string being examined")) to drop any last space. Good thing you took a LEN() for the TRIM()-wrapped string, eh?
OK, So you have a value now that is 1 higher than you need so subtract 1 from it and use the result as the length to specify in a LEFT() function (instead of 20):
=TRIM( LEFT( "source string", "length found above" ))
2nd caveat: Does a string ending in "Mr." satisfy? Or would one, on reflection, like such things also removed? If not, awesome, much easier. If so, and it would be a perfectly valid way to think, if one saw such as always needing the name following, and therefore it is not a valid "word" since it is missing a portion of the slightly more broadly conceived definition of "word" -- one often finds even simple things like "word" can go sideways on one. I won't even try to demonstrate anything to deal with all the weirdness that could occur here except to offer that one could, upon finding such, have another searching clause subtract 1 from the earlier searching result and so finding the next to last space rather than the last... etc.
Then apply it to a reasonably large data set and look for failures due to rare or infrequent things you did not think of being present in your source data...
Sorry to seem cynical there, but we all know the nature of a beast like this. It's definitely live and learn! Keep adding to the OR() clause and making other adjustments to help clean the data for the actual final test.
New contributor
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
add a comment |
There is nothing, really, one can do with formulas that will check the last "word" (string of letters) is a full word. Even if you loaded a monster dictionary to spellcheck against (formula methodology would be loading it in a way that a function such as SEARCH() or VLOOKUP() can search it), there could easily be valid words not contained in it.
One could check the final "word" for things like numerals or punctuation, but then there's the whole "Even though I say "word", what qualifies that is not really a word?" problem. For instance, would an email address be a valid word? Would it only be if it were complete? How about a hashtag word or phrase? How would one even know that is complete or check its spelling since a hashtag word might be "#ijyrrbt8"?
Alright, that aside, my approach would be to first check the last character of a 21 (not 20) character string. If it were a space, or any valid punctuation for the language in question, then I'd consider anything preceding it to be complete and therefore a valid word. Do so using an IF() test on a simple OR() clause. The OR() clause would be simple, though perhaps very long, depending upon all the ways a language might continue, especially with punctuation, after a valid word. Sadly, punctuation occurs INSIDE words too as a marker, for instance, of a contraction taking place: "don't" being an example in English.
After determining that, you are either done (say a space follows, I would consider the preceding "word" to be a valid word... except as noted at the end...), or not done. If not done, one moves on to reducing the 20 character string by stripping the offending end string in it. There is a "trick" used to make FIND() work here (it needs an instance number of what you seek to look for and won't take something like "last", sadly). One uses SUBSTITUTE() to eliminate all the spaces from the cell, or string in this case, taking the LEN() of the result (subtracting it from the LEN() of the original, but you know that is 20, so... well, except you don't (see just after the example formula) so take a LEN() of the string). The result is how many of the searched for characters are present in the string. Let's say the calculation result is 4 when searching for spaces. Therefore, there are four "spaces" in the 20 character string and you can use find to locate the last one:
=FIND( " ", 4 )
Caveat: since the string COULD have a space itself as character 20, wrap the LEFT() with TRIM(): TRIM(LEFT("20 character string being examined")) to drop any last space. Good thing you took a LEN() for the TRIM()-wrapped string, eh?
OK, So you have a value now that is 1 higher than you need so subtract 1 from it and use the result as the length to specify in a LEFT() function (instead of 20):
=TRIM( LEFT( "source string", "length found above" ))
2nd caveat: Does a string ending in "Mr." satisfy? Or would one, on reflection, like such things also removed? If not, awesome, much easier. If so, and it would be a perfectly valid way to think, if one saw such as always needing the name following, and therefore it is not a valid "word" since it is missing a portion of the slightly more broadly conceived definition of "word" -- one often finds even simple things like "word" can go sideways on one. I won't even try to demonstrate anything to deal with all the weirdness that could occur here except to offer that one could, upon finding such, have another searching clause subtract 1 from the earlier searching result and so finding the next to last space rather than the last... etc.
Then apply it to a reasonably large data set and look for failures due to rare or infrequent things you did not think of being present in your source data...
Sorry to seem cynical there, but we all know the nature of a beast like this. It's definitely live and learn! Keep adding to the OR() clause and making other adjustments to help clean the data for the actual final test.
New contributor
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
add a comment |
There is nothing, really, one can do with formulas that will check the last "word" (string of letters) is a full word. Even if you loaded a monster dictionary to spellcheck against (formula methodology would be loading it in a way that a function such as SEARCH() or VLOOKUP() can search it), there could easily be valid words not contained in it.
One could check the final "word" for things like numerals or punctuation, but then there's the whole "Even though I say "word", what qualifies that is not really a word?" problem. For instance, would an email address be a valid word? Would it only be if it were complete? How about a hashtag word or phrase? How would one even know that is complete or check its spelling since a hashtag word might be "#ijyrrbt8"?
Alright, that aside, my approach would be to first check the last character of a 21 (not 20) character string. If it were a space, or any valid punctuation for the language in question, then I'd consider anything preceding it to be complete and therefore a valid word. Do so using an IF() test on a simple OR() clause. The OR() clause would be simple, though perhaps very long, depending upon all the ways a language might continue, especially with punctuation, after a valid word. Sadly, punctuation occurs INSIDE words too as a marker, for instance, of a contraction taking place: "don't" being an example in English.
After determining that, you are either done (say a space follows, I would consider the preceding "word" to be a valid word... except as noted at the end...), or not done. If not done, one moves on to reducing the 20 character string by stripping the offending end string in it. There is a "trick" used to make FIND() work here (it needs an instance number of what you seek to look for and won't take something like "last", sadly). One uses SUBSTITUTE() to eliminate all the spaces from the cell, or string in this case, taking the LEN() of the result (subtracting it from the LEN() of the original, but you know that is 20, so... well, except you don't (see just after the example formula) so take a LEN() of the string). The result is how many of the searched for characters are present in the string. Let's say the calculation result is 4 when searching for spaces. Therefore, there are four "spaces" in the 20 character string and you can use find to locate the last one:
=FIND( " ", 4 )
Caveat: since the string COULD have a space itself as character 20, wrap the LEFT() with TRIM(): TRIM(LEFT("20 character string being examined")) to drop any last space. Good thing you took a LEN() for the TRIM()-wrapped string, eh?
OK, So you have a value now that is 1 higher than you need so subtract 1 from it and use the result as the length to specify in a LEFT() function (instead of 20):
=TRIM( LEFT( "source string", "length found above" ))
2nd caveat: Does a string ending in "Mr." satisfy? Or would one, on reflection, like such things also removed? If not, awesome, much easier. If so, and it would be a perfectly valid way to think, if one saw such as always needing the name following, and therefore it is not a valid "word" since it is missing a portion of the slightly more broadly conceived definition of "word" -- one often finds even simple things like "word" can go sideways on one. I won't even try to demonstrate anything to deal with all the weirdness that could occur here except to offer that one could, upon finding such, have another searching clause subtract 1 from the earlier searching result and so finding the next to last space rather than the last... etc.
Then apply it to a reasonably large data set and look for failures due to rare or infrequent things you did not think of being present in your source data...
Sorry to seem cynical there, but we all know the nature of a beast like this. It's definitely live and learn! Keep adding to the OR() clause and making other adjustments to help clean the data for the actual final test.
New contributor
There is nothing, really, one can do with formulas that will check the last "word" (string of letters) is a full word. Even if you loaded a monster dictionary to spellcheck against (formula methodology would be loading it in a way that a function such as SEARCH() or VLOOKUP() can search it), there could easily be valid words not contained in it.
One could check the final "word" for things like numerals or punctuation, but then there's the whole "Even though I say "word", what qualifies that is not really a word?" problem. For instance, would an email address be a valid word? Would it only be if it were complete? How about a hashtag word or phrase? How would one even know that is complete or check its spelling since a hashtag word might be "#ijyrrbt8"?
Alright, that aside, my approach would be to first check the last character of a 21 (not 20) character string. If it were a space, or any valid punctuation for the language in question, then I'd consider anything preceding it to be complete and therefore a valid word. Do so using an IF() test on a simple OR() clause. The OR() clause would be simple, though perhaps very long, depending upon all the ways a language might continue, especially with punctuation, after a valid word. Sadly, punctuation occurs INSIDE words too as a marker, for instance, of a contraction taking place: "don't" being an example in English.
After determining that, you are either done (say a space follows, I would consider the preceding "word" to be a valid word... except as noted at the end...), or not done. If not done, one moves on to reducing the 20 character string by stripping the offending end string in it. There is a "trick" used to make FIND() work here (it needs an instance number of what you seek to look for and won't take something like "last", sadly). One uses SUBSTITUTE() to eliminate all the spaces from the cell, or string in this case, taking the LEN() of the result (subtracting it from the LEN() of the original, but you know that is 20, so... well, except you don't (see just after the example formula) so take a LEN() of the string). The result is how many of the searched for characters are present in the string. Let's say the calculation result is 4 when searching for spaces. Therefore, there are four "spaces" in the 20 character string and you can use find to locate the last one:
=FIND( " ", 4 )
Caveat: since the string COULD have a space itself as character 20, wrap the LEFT() with TRIM(): TRIM(LEFT("20 character string being examined")) to drop any last space. Good thing you took a LEN() for the TRIM()-wrapped string, eh?
OK, So you have a value now that is 1 higher than you need so subtract 1 from it and use the result as the length to specify in a LEFT() function (instead of 20):
=TRIM( LEFT( "source string", "length found above" ))
2nd caveat: Does a string ending in "Mr." satisfy? Or would one, on reflection, like such things also removed? If not, awesome, much easier. If so, and it would be a perfectly valid way to think, if one saw such as always needing the name following, and therefore it is not a valid "word" since it is missing a portion of the slightly more broadly conceived definition of "word" -- one often finds even simple things like "word" can go sideways on one. I won't even try to demonstrate anything to deal with all the weirdness that could occur here except to offer that one could, upon finding such, have another searching clause subtract 1 from the earlier searching result and so finding the next to last space rather than the last... etc.
Then apply it to a reasonably large data set and look for failures due to rare or infrequent things you did not think of being present in your source data...
Sorry to seem cynical there, but we all know the nature of a beast like this. It's definitely live and learn! Keep adding to the OR() clause and making other adjustments to help clean the data for the actual final test.
New contributor
New contributor
answered 4 hours ago
RoyRoy
1
1
New contributor
New contributor
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
add a comment |
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
(1) Hello again! Will you please register an account, and stop creating new accounts? (2) Is there an answer here?
– Scott
2 hours ago
add a comment |
Kevin R Breen is a new contributor. Be nice, and check out our Code of Conduct.
Kevin R Breen is a new contributor. Be nice, and check out our Code of Conduct.
Kevin R Breen is a new contributor. Be nice, and check out our Code of Conduct.
Kevin R Breen is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1429092%2fdisplay-a-string-from-another-cell-cutting-off-any-word-fragments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
That will be very difficult unless you have a way of defining incomplete words ...
– DavidPostill♦
16 hours ago
1
I am not sure whether I understand you correctly. You write
LEN
here in your post, but you useLEFT
in your screenshot. I guess it has to be the latter, becaueLEN
doesn't have more than one argument. So you always want to cut off at the 20th character of that string? But if a word is cut off in the middle, then you want to exclude the word and stop earlier than at the 20th character?– padawan_IT
16 hours ago
The task can be easily solved using user-defined function (VBA code). Is it safe for you?
– Akina
16 hours ago
@Akina No it can't unless he defines what makes an incomplete word.
– DavidPostill♦
15 hours ago