Mid function query

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Pls Note: The following query answer i got from one of our MrExcel Member, but this is some applicable to limited no. of result, hence query asking again.

The solution I got that is-
=MID(F12,1,FIND(".",F12)-1)&MID(F12,FIND(" ",F12),FIND(".",F12,FIND(" ",F12))-FIND(" ",F12))

My query was, i have data like,
Tag No.
P01.SG-17 P01B.SG-18
P01.SG-17 P01A.SG-25
P05.SG-21 P05A.SG-22
P02.SG-11
P02.SG-12
P07.SG-12 P07A.SG-15 P07B.SG-16

O/p should be -
P01 P01B
P01 P01A
P05 P05A
P02
P02
P07 P07A P07B

The reason i red marked, the formula is fixed. That made for 2 naming convention only. Not Single ("P02.SG-11") or for three content.
That is, if set this much only-
=MID(F12,1,FIND(".",F12)-1)&MID(F12,FIND(" ",F12))
then this will applicable to only single naming convetions.

I dont want this.
tag no. can be any length of content. Only SG tag dont want to display.
Tha is from 1st "." to space and like way.

Can any one there to SOLVE problem?

I am also trying some R&D, by using SUBSTITUTE function.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
A custom user defined function perhaps?
=StripTag(A1)
backed up by a function:
Code:
Function StripTag(r As String) As String
With CreateObject("vbscript.regexp")
  .Pattern = "\.[A-Za-z]+\-[0-9]+"
  Do
    X = Len(r)
    r = Trim(.Replace(r, ""))
  Loop Until Len(r) = X
End With
StripTag = r
End Function
Now I'm not familiar with regex, and I don't know how to search for all instances of a pattern in a string using it, hence the loop.
The pattern that this one looks for is:
a dot, then a sequence of consecutive alpha characters, then a hyphen, then a sequence of consecutive numerals.
I'm sure it could be better.
Excel Workbook
AB
9P01.SG-172 P01B.SG-18P01 P01B
10P01.SG-17 P01A.SG-25P01 P01A
11P05.Sg-21 P05A.SG-22P05 P05A
12P02.SG-11P02
13P02.SG-12P02
14P07.SG-12 P07A.SG-15 P07B.SG-16P07 P07A P07B
Sheet
 
Upvote 0
I am really thankful by so much kind attention.

I had applied the same as ur advised.
in cell b1 it looks like this - #Name?

even i am not got this, what xctly this?

in backend i simply copy and paste this code.
then in each cells in Col b I wrote =StripTag(A1)
but nothing.

It helps mi great, if pls help for this.
 
Upvote 0
A custom user defined function perhaps?
=StripTag(A1)
backed up by a function:
Code:
Function StripTag(r As String) As String
With CreateObject("vbscript.regexp")
  .Pattern = "\.[A-Za-z]+\-[0-9]+"
  Do
    X = Len(r)
    r = Trim(.Replace(r, ""))
  Loop Until Len(r) = X
End With
StripTag = r
End Function
Now I'm not familiar with regex, and I don't know how to search for all instances of a pattern in a string using it, hence the loop.
The pattern that this one looks for is:
a dot, then a sequence of consecutive alpha characters, then a hyphen, then a sequence of consecutive numerals.
I'm sure it could be better.
Excel Workbook
AB
9P01.SG-172 P01B.SG-18P01 P01B
10P01.SG-17 P01A.SG-25P01 P01A
11P05.Sg-21 P05A.SG-22P05 P05A
12P02.SG-11P02
13P02.SG-12P02
14P07.SG-12 P07A.SG-15 P07B.SG-16P07 P07A P07B
Sheet

I was working on this and thought of checking back this post and found out this AMAZING ( :beerchug: ) solution already posted...

couldn't resist to leave a feed back...


Thanks for the share of this new code (atleast for me)...
 
Upvote 0
I was working on this and thought of checking back this post and found out this AMAZING ( :beerchug: ) solution already posted...

couldn't resist to leave a feed back...


Thanks for the share of this new code (atleast for me)...

Thank you for the feed back!
 
Upvote 0
Pls guys, help me.
Not working at my end. Kindly tell me the solution. I also wanted to enjoy this trick lik u guys.
 
Upvote 0
On the workbook press Alt+F11
Insert a new module and paste the code mentioned...

Then in the workbook in the cell B1 this formula..
=StripTag(A1)
and copy paste this formula till the end of column B for which you want the values
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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