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