Extract last two characters from the middle of a dataset name

markzasz

New Member
Joined
Aug 12, 2015
Messages
29
I have multiple files containing thousands of datasets names and I need to extract the last two characters from the second level of the dataset, below is an example of a files and what I am looking for.

file before:

A B C
Dataset name Volume CUA
PMXGS.MKTCH.LOADLIBC
CMOCI0
B325
PMXRA.EXICH.LOADLIBC
CMOCI0
B325
PMXRA.PFRCH.LOADLIBC
CMOCI0
B325
PMXRA.ZBGCH.LOADLIBC
CMOCI0
B325
PMXRA.ZJJCH.LOADLIBC
CMOCI0
B325
PMXRS.CONCH.LOADLIBC
CMOCI0
B325

<tbody>
</tbody>


What I want it to look like is this:

A B C D
Dataset name Volume CUA Last two
PMXGS.MKTCH.LOADLIBC
CMOCI0
B325
CH
PMXRA.EXIBZ.LOADLIBC
CMOCI0
B325
BZ
PMXRA.PFR7C.LOADLIBC
CMOCI0
B325
7C
PMXRA.ZBGCH.LOADLIBC
CMOCI0
B325
CH
PMXRA.ZJJCM.LOADLIBC
CMOCI0
B325
CM
PMXRS.CONDH.LOADLIBC
CMOCI0
B325
DH

<tbody>
</tbody>


Mark
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
some VBA
Code:
Sub t()
Dim c As Range, spl As Variant
With ActiveSheet
    For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
        spl = Split(c.Value, ".")
        c.Offset(, 3) = Right(spl(1), 2)
    Next
End With
End Sub
 
Upvote 0
Assuming your examples are representative of your actual data, then here is a formula that you can use...

=RIGHT(TRIM(MID(SUBSTITUTE(A2,".",REPT(" ",200)),200,200)),2)
 
Last edited:
Upvote 0
I have multiple files containing thousands of datasets names and I need to extract the last two characters from the second level of the dataset, below is an example of a files and what I am looking for.

file before:

A B C
Dataset name Volume CUA
PMXGS.MKTCH.LOADLIBC CMOCI0 B325
PMXRA.EXICH.LOADLIBC CMOCI0 B325
PMXRA.PFRCH.LOADLIBC CMOCI0 B325
PMXRA.ZBGCH.LOADLIBC CMOCI0 B325
PMXRA.ZJJCH.LOADLIBC CMOCI0 B325
PMXRS.CONCH.LOADLIBC CMOCI0 B325

<tbody>
</tbody>


What I want it to look like is this:

A B C D
Dataset name Volume CUA Last two
PMXGS.MKTCH.LOADLIBC CMOCI0 B325 CH
PMXRA.EXIBZ.LOADLIBC CMOCI0 B325 BZ
PMXRA.PFR7C.LOADLIBC CMOCI0 B325 7C
PMXRA.ZBGCH.LOADLIBC CMOCI0 B325 CH
PMXRA.ZJJCM.LOADLIBC CMOCI0 B325 CM
PMXRS.CONDH.LOADLIBC CMOCI0 B325 DH

<tbody>
</tbody>
There is a simple forumala for this =MID(A1,10,2)
 
Upvote 0
There is a simple forumala for this =MID(A1,10,2)
Looks like you made a good observation. If, in fact, each of the first two fields are always five characters long, then your simple formula will work fine. However, if the fields can vary in length, then the OP would need the formula I posted in Message #3 instead.
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,313
Members
449,152
Latest member
PressEscape

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