To return
Azate Tabs-25mg
from your original line, I returned everything from the last "\" to the third "-" below.
Excel worksheet function:
=LEFT(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99)), "-",CHAR(1),3),FIND(CHAR(1),SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE( A1,"\",REPT(" ",99)),99)),"-",CHAR(1),3))-1)
Custom function:
Option Explicit Function Meds(S As String) As String Dim S1 As Variant, S2 As Variant S1 = Split(S, "\") S2 = Split(S1(UBound(S1)), "-") ReDim Preserve S2(0 To 2) Meds = Join(S2, "-") End Function
source share