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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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,215,461
Messages
6,124,957
Members
449,200
Latest member
indiansth

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