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?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about
Excel Formula:
=TRIM(MID(A2,FIND("|",SUBSTITUTE(A2,"-","|",2))+1,99))
 
Upvote 0
Try: =MID(A1,FIND(CHAR(135),SUBSTITUTE(A1,"-",CHAR(135),2))+2,9999)
 
Upvote 0
i appreciate the responses, i forgot to mention that i'm trying to do this in VBA. will this still work?
 
Upvote 0
How about
VBA Code:
Sub termeric()
   Dim Cl As Range
   
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 1).Value = Trim(Split(Cl, "-", 3)(2))
   Next Cl
End Sub
If you can a cell with only 1 hyphen this will fail, let me know if that is a possibility.
 
Upvote 0
How about
VBA Code:
Sub termeric()
   Dim Cl As Range
  
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Cl.Offset(, 1).Value = Trim(Split(Cl, "-", 3)(2))
   Next Cl
End Sub
If you can a cell with only 1 hyphen this will fail, let me know if that is a possibility.


This works, i had to modify it a bit so that i am taking the ID & SubID and the hypehen between

Code:
Cl.Offset(, 1).Value = Trim(Split(Cl, "-", 3)(1) & "-" & Trim(Split(Cl, "-", 3)(2)))
[\code]

much appreciated
 
Upvote 0
There should have been no need to modify it, this is what I get
+Fluff 1.xlsm
AB
1
2Category - Name - ID - SubIDID - SubID
Main

If you are only getting the SubId, then you do not have 2 - before the ID. I suspect the the hyphen between the Category & Name is not a true hyphen.
 
Upvote 0
is it possible to read this from the right instead of the left? i know the back two are hyphens
 
Upvote 0
can you post som actual samples of your data, they way we can find out what the other - actually is?
 
Upvote 0
[Middle Market] New Invoice for Customer AAA-86580531-2612021114547
Public & Labor- New Invoice for Customer BBB-0838904-2612021134611
Middle Market- New Invoice for Customer CCC-143257-261202114184
Middle Market- New Invoice for Customer CCC-143257-261202114316
 
Upvote 0

Forum statistics

Threads
1,216,090
Messages
6,128,765
Members
449,467
Latest member
sdafasfasdf

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