C22K001
C15K015A
FA28K005A
Hi,
Could someone help me to split the cell and drop the prefixes C and FA as
well as the suffix A? What will be left will read 22K-001, 15K-015 or 28K-005.
Thanks for the help.
Ray
Here's a UDF (user defined function) that should accomplish that.
To enter this User Defined Function (UDF), <alt-F11> opens the Visual Basic
Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.
To use this User Defined Function (UDF), enter a formula like
=SplitPrefixSuffix(A1)
in some cell.
The assumptions:
*Prefix is 0 to n capital letters
followed by
1-n digits
followed by
1-n capital letters
followed by
1-n digits
followed by
*Suffix of 0-n capital letters
*Prefix and suffix are removed.
A hyphen is placed after the middle capital letter(s).
=======================
Option Explicit
Function SplitPrefixSuffix(s As String) As String
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "[A-Z]*(\d+)([A-Z]+)(\d+)[A-Z]*"
SplitPrefixSuffix = re.Replace(s, "$1$2-$3")
End Function
=======================
--ron