I am trying to split the cell content with length greater than 72 into separate rows with their length not increasing more than 72 chars. I am not able to thing through this logic and need help. Special challenge here is that the content of each cell is is a complete sentence and has no delimiter, so I need to divide the statement only when a word ends and also having length 72 chars preserved for each cell and not more than that.
Any suggestions?
Thanks
You can do this using regular expressions. Try adapting this macro, which I wrote some time ago, to your specific requirements: If a word should happen to be longer than
w
characters, it will overflow -- probably not a problem with 72 character line length; but you can change that behavior by changing the regex.As written, the macro will write the split text into cells below the original.
Example using your original post as the data in one cell:
Here is an explanation and links to explanations regarding the line-splitting regular expression, as it would be rendered with a line length of 72 characters.
\S.{0,71}(?=\s|$)|\S{72,}
Options: Case sensitive; ^$ match at line breaks (irrelevant in this instance)
\S.{0,71}(?=\s|$)
\S
.{0,71}
{0,71}
(?=\s|$)
\s
\s
$
$
\S{72,}
\S{72,}
{72,}
Created with RegexBuddy
EDIT At the request of the original poster, a routine was added which would cycle through the cells in column A, placing the results of the splitting into column B. Some of the original code, allowing selection of line length and source selection, was hard-coded.
How about this: