I want to Remove the Line Break from the string if my string Ends with Line Break.
Sub linebreak(myString)
If Len(myString) <> 0 Then
If Rig
I had the exact same issue. I made a separate function I can call easily when needed:
Function removeLineBreakIfAtEnd(s As String) As String
If Right(s, 1) = vbLf Then s = Left(s, Len(s) - 2)
removeLineBreakIfAtEnd = s
End Function
I found that I needed to check the last character only and do -2 to remove the line break. I also found that checking for vbLf was the ONLY way to detect the line break. The function can be called like this:
Sub MainSub()
Dim myString As String
myString = "Hello" & vbCrLf
myString = removeLineBreakIfAtEnd(myString)
MsgBox ("Here is the resulting string: '" & myString & "'")
End Sub