Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Characters 2

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need an if statement saying if the last 5 characters of a string = something specific, then remove all 5. After finding the last 5 characters, anyone know what I need to use to remove them from the string?

TIA!
 
If Right$("String",5) = "Specific5char" Then
"String" = Left$("String", Len("String")- 5)
End if

Robert
 
Use the mid(), right() and left() functions to test and get parts of a string.

Once you have the part that you want save it into your original variable.

Good Luck
 
You could use:
Const KillString = "78HJY"
Dim MyString As String
MyString = "123abd78hjy"

If UCase(Right(Trim(MyString), 5)) = KillString Then
MyString = Left(MyString, (InStr(1, MyString, KillString) - 1))
Debug.Print MyString
End If
 
All suggestions work. "TheVampire"'s code is most concise.
"Wizsh" uses mid() - which does the samething, but allows you to SPECIFY the beginning of the string; left() ALWAYS
uses the left end as the beginning. "RobertT687" solution
is most complete, but quite involved.
I'd go with "TheVampire"'s as most "incorporate-able.
 

Replace myString, StringToFind, vbNullString, Len(myString)-5,5
 
CCLINT's suggestion is better than mine. I didn't even think of REPLACE...

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top