Finding all text to the right a the second hyphen

termeric

Active Member
Joined
Jun 21, 2005
Messages
280
Hello, i'm trying to figure out how to isolate the text to on the right side after the second hyphen. my text string looks like this Category - Name - ID - SubID so i want to only take ID and Sub ID. how can count the number of characters to the right of the second hyphen from the right?
 
so what i want to end up with is
86580531-2612021114547
0838904-2612021134611
143257-261202114184
143257-261202114316
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Ok, so some times you will only have two hyphens in the cell, correct?
 
Upvote 0
Assuming your existing data is in Column A and you want your answers in Column B, give this macro a try...
VBA Code:
Sub GetLastTwoDashedNumbers()
  With Range("A2", Cells(Rows.Count, "A").End(xlUp))
    .Offset(, 1) = Evaluate(Replace("IF({1},SUBSTITUTE(@,""-"",""|"",LEN(@)-LEN(SUBSTITUTE(@,""-"",""""))-1))", "@", .Address))
    .Offset(, 1).TextToColumns , xlDelimited, , , False, False, False, False, True, "|", Array(Array(1, 9), Array(2, 2))
  End With
End Sub
 
Upvote 0
Ok, another option
VBA Code:
Sub termeric()
   Dim Cl As Range
   
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 1).Value = Mid(Cl.Value, InStrRev(Cl.Value, "-", InStrRev(Cl.Value, "-") - 1) + 1)
   Next Cl
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top