I have this string:
AAAAAAA
in need to check if the last caharcter in string is a blank end delete it if exists...
note:
i dont remember if i just oost this question but not found in my old post
DELETE the last character in string if is a blank space
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78530
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: DELETE the last character in string if is a blank space
If you want to delete ALL leading and trailing spaces, you can use Trim:
MyVar will then be "AAA"
Otherwise:
Code: Select all
Dim MyVar As String
MyVar = " AAA "
MyVar = Trim(MyVar)
Otherwise:
Code: Select all
If Right(MyVar, 1) = " " Then
MyVar = Left(MyVar, Len(MyVar) - 1)
End If
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4362
- Joined: 26 Apr 2010, 17:36
Re: DELETE the last character in string if is a blank space
great!HansV wrote:If you want to delete ALL leading and trailing spaces, you can use Trim:
MyVar will then be "AAA"Code: Select all
Dim MyVar As String MyVar = " AAA " MyVar = Trim(MyVar)
Otherwise:
Code: Select all
If Right(MyVar, 1) = " " Then MyVar = Left(MyVar, Len(MyVar) - 1) End If
-
- Microsoft MVP
- Posts: 1318
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: DELETE the last character in string if is a blank space
Also look up the functions LTrim (removes all leading spaces) and RTrim (removes all trailing spaces).
http://office.microsoft.com/en-us/excel ... 57211.aspx" onclick="window.open(this.href);return false;
http://office.microsoft.com/en-us/excel ... 57211.aspx" onclick="window.open(this.href);return false;