Remove newline char from string
Hi Robert,
Am Wed, 18 Mar 2015 23:47:41 -0700 schrieb Robert Crandal:
BTW, I am only concerned about extra newlines at the beginning
or end of the string. It is okay to have newline characters
in the middle of the string.
try:
Sub Test()
Dim myStr As String
myStr = Range("A1")
With Application
If InStr(.Trim(myStr), Chr(10)) = 1 Then
Do
myStr = Right(.Trim(myStr), Len(myStr) - 1)
Loop While InStr(.Trim(myStr), Chr(10)) = 1
End If
If InStrRev(.Trim(myStr), Chr(10)) = Len(.Trim(myStr)) Then
Do
myStr = .Trim(Left(.Trim(myStr), Len(.Trim(myStr)) - 1))
Loop While InStrRev(.Trim(myStr), Chr(10)) = Len(.Trim(myStr))
End If
End With
Range("A1") = myStr
End Sub
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|