So while I agree
=LEFT(REPLACE(A1,1,79,""),FIND("-",REPLACE(A1,1,79,""),FIND(".",REPLACE(A1,1,79,"")))-1)
Does the trick... I prefer to never lock down string counts when it is based on variables throughout the code. The above will work if you 100% of the time will maintain your format.
Here is the process in VB as well - personally I like VB because there is nothing calculating in my workbooks when I open it - just the results pushed when desired -
You will need to modify the code as I am sure your data doesnt live in column A and start on 2... likely something you are working in...although if it is text like you provided you could just paste it in A2 and not have to modify the code below.
Sub StringExtraction()
Dim i As Long 'The Row being evaluated (Set to first row, likely 2)
Dim c As Long 'The Column of your Data
Dim rc As Long 'The column of your results
'Note - Columns are numbered left to right A being 1
Dim LastRow As Long 'Limit the loop to the last row used in your data
Dim LVal As Long 'How many characters from the left will we return
Dim RVal As Long 'How many characters from the right will we return
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
i = 2
c = 1
rc = 2
'We will loop through your list until it has hit the end
Do Until i > LastRow
'Find the LAST Hyphen in your string Less 1 for the position of the hyphen
LVal = InStrRev(Cells(i, c), "-", -1) - 1
'Find the LAST Hyphen and the LAST forward slash and get the difference between them Less 1 for the position of the forward slash
RVal = InStrRev(Cells(i, c), "-", -1) - InStrRev(Cells(i, c), "/", -1) - 1
'Error catching for when your value being evaluated does not contain a Hyphen "-" after a forward slash "/"
If LVal < 1 Or RVal < 1 Then
Cells(i, rc).Value = "UnKnown Format"
Else: Cells(i, rc).Value = Right(Left(Cells(i, c), LVal), RVal)
End If
i = i + 1
Loop
End Sub
Cheers
Bookmarks