0

I got results from Outlook into Excel using VBA. There are some cells that hold multiple lines in one cell, like this

line 1
line 2



another line


final line

I tried regular expression "^$" to remove the empty lines.

And worse, since all the lines are in once cell, I cannot use a formula to merge them.

What is in between the lines? I used "^$" to match them and replace with "". That means there is nothing left but still the empty lines are there. I also removed "chr(13)".

1
  • The symbol between the lines is chr(10). Your change crossed my answer, so I edited it.
    – GolezTrol
    Nov 19, 2010 at 21:46

1 Answer 1

1

Do you want to remove all line breaks?

YourResult = replace(replace(YourCellValue, chr(10), ""), chr(13), "")

Or do you just want to remove the empty lines?

[edit] The answer above wasn't tested. I see now that the character separating the lines is chr(10), so you only need to replace that:

YourResult = replace(YourCellValue, chr(10), "")

Also, if you want to keep multiple lines, but remove the empty lines, you can replace two line breaks with one, and repeat that step until no changes are left:

Function FixLines(value As String)
  Do
    s = value
    value = Replace(value, Chr(10) & Chr(10), Chr(10))
  Loop Until value = s
  FixLines = value
End Function

YourResult = FixLines(YourCellValue)
1
  • this is the best answer to this issue along this line - among all the answers I googled. THANK YOU, GolezTol!
    – john
    Nov 19, 2010 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.