View Single Post
 
Old 07-09-2018, 11:33 AM
ArviLaanemets ArviLaanemets is offline Windows 8 Office 2016
Expert
 
Join Date: May 2017
Posts: 949
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

The worksheet formula is like (assumed the text is in cell A2, on fly)
Code:
=IFERROR(RIGHT(A2,Find("_",A2)), A2)
Sorry! With Office 2010
Code:
=IF(ISERROR(RIGHT(A2,Find("_",A2)-1)), A2,RIGHT(A2,Find("_",A2)))
When you need this in VBA, then instead FIND() you have to use InStr(), and If ... End If to handle cases when the string is not found (then InStr() returns 0).
Something like:
Code:
If InStr(SourceVariable, "_") = 0 Then
     ResultVariable = SourceVariable
Else
     ResultVariable = Right(SourceVariable, Len(SourceVariable) - InStr(SourceVariable, "_"))
End If
Reply With Quote