Searching for a substring in a string after a specific number of specific characters

rozias

New Member
Joined
Jan 23, 2017
Messages
1
I am trying to extract a substring from a string that contains a varying number of characters. Example: BLAH BLAH TRN#1#0000000000#9999999999

I would like to identify just the 0's in the example string. I have been using the MID function (below), but the issues is with the number of 0's. It can vary in length.

=MID(A1,FIND("TRN#1#",A1)+6,10)

If there were only nine 0's, then my result would be 000000000#. Basically, I want to trim all characters from the last "#" and then run my MID function. Any help would be greatly appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
see if this will work for you.

Code:
Sub t()
Dim spl As Variant, c As Range
For Each c In Range("A2:A1000") 'Range is arbitrary, use actual
    spl = Split(c.Value, "#")
        MsgBox spl(UBound(spl) - 1)
Next
End Sub
 
Upvote 0
Try this instead...
=MID(A1,FIND("TRN#1#",A1)+6,LEN(A1)-LEN(SUBSTITUTE(A1,0,"")))

Note this will NOT work of there are 0's anywhere else in the string
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,043
Members
449,092
Latest member
ikke

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