You are on page 1of 13

Dear all,

I have a question pertaining to extract middle characters either Numbers or


Text.
ABC-1236-FHGKG
CD-1556598-12236
ABC 1236 FHGKS
CD/1556598/12236
FRTTF/12336569/FG
I want the middle characters as follows->
1236
1556598
1236
1556598
12336569
Any worksheet function apart from using Macros ?
Warm regards
Dharmesh

Assuming that the "delimiting characters" are always present as "a pair" and only one
such pair exists inside each string, try this formula to get the "middle characters" from the
string in cell A1:
=MID(A1,MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/ "))),ROW($1:$100)))-2)
Note: This is an array formula that has to be confirmed with CTRL+SHIFT+ENTER
rather than just ENTER.
The number 100 in $1:$100 is chosen to take care of string of lenght 100. Increase if
needed.
If you have a need for other "delimiting characters" besides "-", "/", and " ", then just
modifiy the string "-/ " to contain also these characters.
Hope this helps / Lars-Åke
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote

Here is an array-entered** formula for you to try...


=LOOKUP(9E+99,--LEFT(MID(A1,MIN(FIND(ROW($1:$10)-
1,A1&"0123456789")),99),ROW($1:$99)))
** Commit formula using CTRL+SHIFT+ENTER, not just Enter by itself.
NOTE: Please mark the message or messages (yes, you can mark more than one) that
answer your question as the "Answer" so that others will know your question has been
resolved.
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote
Actually, since you are probably going to copy this formula down, perhaps past existing
data in anticipation of future data, then this version of my array-entered** fromula would
probably be better to use...
=IF(A1="","",LOOKUP(9.9E+307,--LEFT(MID(A1,MIN(FIND(ROW($1:$10)-
1,A1&"0123456789")),99),ROW($1:$99))))
** Commit formula using CTRL+SHIFT+ENTER, not just Enter by itself.

NOTE: Please mark the message or messages (yes, you can mark more than one) that
answer your question as the "Answer" so that others will know your question has been
resolved.
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote

With any of your posted examples in cell A1..try this regular formula:

=LOOKUP(99^99,--
("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$100
00))))

These are the value/returned values:


ABC-1236-FHGKG 1236
CD-1556598-12236 1556598
ABC 1236 FHGKS 1236
CD/1556598/12236 1556598
FRTTF/12336569/FG 12336569

Is that something you can work with?

Ron Coderre
Microsoft MVP (2006 - 2010) - Excel
P.S. If any post answers your question, please mark it as the Answer (so it won't keep
showing as an open item.)
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote
"Dharmesh" wrote...
>I have a question pertaining to extract middle characters either Numbers
or
>Text.
>
>ABC-1236-FHGKG
>
>CD-1556598-12236
>
>ABC 1236 FHGKS
>
>CD/1556598/12236
>
>FRTTF/12336569/FG
>
>I want the middle characters as follows->
>
>1236
>
>1556598
>
>1236
>
>1556598
>
>12336569
....
Your examples all show numbers (sequences of only decimal numerals) as
the
middle characters. If that's representative, then the approaches others have
offered may work. However, if there could be letters in the middle
characters, and the delimiters were only space, hyphen and slash, it may
be
more robust to use a formula like
=MID(LEFT(A1,FIND({"-","/"," "},A1&"-/ ",FIND({"-","/"," "},A1&"-/
")+1)-1),
FIND({"-","/"," "},A1&"-/ ")+1,255)
@fzz
I can only get your formula to work for the strings where hyphen, "-", is the delimiter.
Doesn't matter if the formula is array entered or not.
Do I mis something here?
Regards / Lars-Åke
P.S. The formula that I proposed will work for any characters (except the three delimiting
characters) in the middle, not just numbers.
Marked As Answer byDharmesh Tuesday, September 14, 2010 1:51 AM
Reply
Quote

Formula to extract left characters from above data,


=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(32),REPT(CH
AR(32),99)),CHAR(45),REPT(CHAR(32),99)),CHAR(47),REPT(CHAR(32),99)),99))
Formula to extract left characters from above data,
=TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(32),REPT(C
HAR(32),99)),CHAR(45),REPT(CHAR(32),99)),CHAR(47),REPT(CHAR(32),99)),99))
These formulas are limited as to what characters can be found as delimiters (e.g. slash,
hyphen or space). A UDF (User Defined Function) could easily be written to use any
character that isn't alphanumeric.

If this proposed solution has resolved your issue(s), please return and mark it as
Answered for others to consider.
Marked As Answer byDharmesh Wednesday, September 15, 2010 2:26 PM
Reply
Quote
\
Dear all,
I have a similar question related to extract characters.
Data->
ABC-1236-FHGKG
25696669-15565985669988996692556-12236
ABC 1236 FHGKS
CD/1556598/12236
FRTTF/12336569/FG
Sufi/Dharmesh/Khan
Sufi Dharmesh Khan
Sufi-Dharmesh-Khan
When i used Lar's below formula, it gave the output as required for
the middle characters. It even handles the longest integers.
=MID(A16,MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),
"-/ "))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)))-2)
Output->
1236
15565985669988996692556
1236
1556598
12336569
Dharmesh
Dharmesh
Dharmesh
My concern is to extract Left & right characters in different columns as
those in case of middle characters irrespective of numbers or text.
Any formula apart from using Macrosor the above formula needs to be
modified?
Formula to extract left characters from the above data ??????
Formula to extract right characters from the above data ??????
Warm regards
Dharmesh
@ Dharmesh
Using parts of the formula for middle characters, here are proposals for the other two
parts:
For the left characters
=LEFT(A1,MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)-1)))
For the right characters
=MID(A1,SMALL(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2),100)
Note: These are array formulas that have to be confirmed with CTRL+SHIFT+ENTER
rather than just ENTER.
The number 100 is chosen to take care of string of lenght 100. Increase if needed.
If you have a need for other "delimiting characters" besides "-", "/", and " ", then just
modifiy the string "-/ " to contain also these characters.
Hope this helps / Lars-Åke
Marked As Answer byDharmesh Wednesday, September 15, 2010 2:26 PM
Reply
Quote
All Replies
Dear all,
I have a question pertaining to extract middle characters either Numbers or
Text.
ABC-1236-FHGKG
CD-1556598-12236
ABC 1236 FHGKS
CD/1556598/12236
FRTTF/12336569/FG
I want the middle characters as follows->
1236
1556598
1236
1556598
12336569
Any worksheet function apart from using Macros ?
Warm regards
Dharmesh

Assuming that the "delimiting characters" are always present as "a pair" and only one
such pair exists inside each string, try this formula to get the "middle characters" from the
string in cell A1:
=MID(A1,MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/ "))),ROW($1:$100)))-2)
Note: This is an array formula that has to be confirmed with CTRL+SHIFT+ENTER
rather than just ENTER.
The number 100 in $1:$100 is chosen to take care of string of lenght 100. Increase if
needed.
If you have a need for other "delimiting characters" besides "-", "/", and " ", then just
modifiy the string "-/ " to contain also these characters.
Hope this helps / Lars-Åke
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote
Here is an array-entered** formula for you to try...
=LOOKUP(9E+99,--LEFT(MID(A1,MIN(FIND(ROW($1:$10)-
1,A1&"0123456789")),99),ROW($1:$99)))
** Commit formula using CTRL+SHIFT+ENTER, not just Enter by itself.

NOTE: Please mark the message or messages (yes, you can mark more than one) that
answer your question as the "Answer" so that others will know your question has been
resolved.
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote

Actually, since you are probably going to copy this formula down, perhaps past existing
data in anticipation of future data, then this version of my array-entered** fromula would
probably be better to use...
=IF(A1="","",LOOKUP(9.9E+307,--LEFT(MID(A1,MIN(FIND(ROW($1:$10)-
1,A1&"0123456789")),99),ROW($1:$99))))
** Commit formula using CTRL+SHIFT+ENTER, not just Enter by itself.

NOTE: Please mark the message or messages (yes, you can mark more than one) that
answer your question as the "Answer" so that others will know your question has been
resolved.
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote

With any of your posted examples in cell A1..try this regular formula:

=LOOKUP(99^99,--
("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$100
00))))

These are the value/returned values:


ABC-1236-FHGKG 1236
CD-1556598-12236 1556598
ABC 1236 FHGKS 1236
CD/1556598/12236 1556598
FRTTF/12336569/FG 12336569
Is that something you can work with?

Ron Coderre
Microsoft MVP (2006 - 2010) - Excel

P.S. If any post answers your question, please mark it as the Answer (so it won't keep
showing as an open item.)
Marked As Answer byDharmesh Monday, September 13, 2010 10:09 AM
Reply
Quote

Dear all,
Thanks for your invaluable time to respond my concern. All the formulas devised by you
Champions work perfectly well. I am highly greatful to you all.
Warm regards
Dharmesh
Reply
Quote
"Dharmesh" wrote...
>I have a question pertaining to extract middle characters either Numbers or
>Text.
>
>ABC-1236-FHGKG
>
>CD-1556598-12236
>
>ABC 1236 FHGKS
>
>CD/1556598/12236
>
>FRTTF/12336569/FG
>
>I want the middle characters as follows->
>
>1236
>
>1556598
>
>1236
>
>1556598
>
>12336569
....
Your examples all show numbers (sequences of only decimal numerals) as the
middle characters. If that's representative, then the approaches others have
offered may work. However, if there could be letters in the middle
characters, and the delimiters were only space, hyphen and slash, it may be
more robust to use a formula like
=MID(LEFT(A1,FIND({"-","/"," "},A1&"-/ ",FIND({"-","/"," "},A1&"-/ ")+1)-1),
FIND({"-","/"," "},A1&"-/ ")+1,255)
Reply
Quote

"Dharmesh" wrote...
>I have a question pertaining to extract middle characters either Numbers
or
>Text.
>
>ABC-1236-FHGKG
>
>CD-1556598-12236
>
>ABC 1236 FHGKS
>
>CD/1556598/12236
>
>FRTTF/12336569/FG
>
>I want the middle characters as follows->
>
>1236
>
>1556598
>
>1236
>
>1556598
>
>12336569
....
Your examples all show numbers (sequences of only decimal numerals) as
the
middle characters. If that's representative, then the approaches others have
offered may work. However, if there could be letters in the middle
characters, and the delimiters were only space, hyphen and slash, it may
be
more robust to use a formula like
=MID(LEFT(A1,FIND({"-","/"," "},A1&"-/ ",FIND({"-","/"," "},A1&"-/
")+1)-1),
FIND({"-","/"," "},A1&"-/ ")+1,255)
@fzz
I can only get your formula to work for the strings where hyphen, "-", is the delimiter.
Doesn't matter if the formula is array entered or not.
Do I mis something here?
Regards / Lars-Åke
P.S. The formula that I proposed will work for any characters (except the three delimiting
characters) in the middle, not just numbers.
Marked As Answer byDharmesh Tuesday, September 14, 2010 1:51 AM
Reply
Quote

Dear Lars,
Your below devised formula can handle numbers as well as text and that's amazing.
=MID(A1,MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/ "))),ROW($1:$100)))-2)
Warm regards
Dharmesh
Reply
Quote
Dear all,
I have a similar question related to extract characters.
Data->
ABC-1236-FHGKG
25696669-15565985669988996692556-12236
ABC 1236 FHGKS
CD/1556598/12236
FRTTF/12336569/FG
Sufi/Dharmesh/Khan
Sufi Dharmesh Khan
Sufi-Dharmesh-Khan
When i used Lar's below formula, it gave the output as required for the middle
characters. It even handles the longest integers.
=MID(A16,MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/ "))),ROW($1:$100)))-
2)
Output->
1236
15565985669988996692556
1236
1556598
12336569
Dharmesh
Dharmesh
Dharmesh
My concern is to extract Left & right characters in different columns as those in case of
middle characters irrespective of numbers or text.
Any formula apart from using Macros or the above formula needs to be modified?
Formula to extract left characters from the above data ??????
Formula to extract right characters from the above data ??????
Warm regards
Dharmesh
Reply
Quote
Formula to extract left characters from above data,
=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(32),REPT(CH
AR(32),99)),CHAR(45),REPT(CHAR(32),99)),CHAR(47),REPT(CHAR(32),99)),99))
Formula to extract left characters from above data,
=TRIM(RIGHT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,CHAR(32),REPT(C
HAR(32),99)),CHAR(45),REPT(CHAR(32),99)),CHAR(47),REPT(CHAR(32),99)),99))
These formulas are limited as to what characters can be found as delimiters (e.g. slash,
hyphen or space). A UDF (User Defined Function) could easily be written to use any
character that isn't alphanumeric.

If this proposed solution has resolved your issue(s), please return and mark it as
Answered for others to consider.
Marked As Answer byDharmesh Wednesday, September 15, 2010 2:26 PM
Reply
Quote

Dear all,
I have a similar question related to extract characters.
Data->
ABC-1236-FHGKG
25696669-15565985669988996692556-12236
ABC 1236 FHGKS
CD/1556598/12236
FRTTF/12336569/FG
Sufi/Dharmesh/Khan
Sufi Dharmesh Khan
Sufi-Dharmesh-Khan
When i used Lar's below formula, it gave the output as required for
the middle characters. It even handles the longest integers.
=MID(A16,MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),
"-/ "))),ROW($1:$100)+1)),
SMALL(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2)-
MIN(IF(NOT(ISERROR(FIND(MID(A16,ROW($1:$100),1),"-/
"))),ROW($1:$100)))-2)
Output->
1236
15565985669988996692556
1236
1556598
12336569
Dharmesh
Dharmesh
Dharmesh
My concern is to extract Left & right characters in different columns as
those in case of middle characters irrespective of numbers or text.
Any formula apart from using Macrosor the above formula needs to be
modified?
Formula to extract left characters from the above data ??????
Formula to extract right characters from the above data ??????
Warm regards
Dharmesh
@ Dharmesh
Using parts of the formula for middle characters, here are proposals for the other two
parts:
For the left characters
=LEFT(A1,MIN(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)-1)))
For the right characters
=MID(A1,SMALL(IF(NOT(ISERROR(FIND(MID(A1,ROW($1:$100),1),"-/
"))),ROW($1:$100)+1),2),100)
Note: These are array formulas that have to be confirmed with CTRL+SHIFT+ENTER
rather than just ENTER.
The number 100 is chosen to take care of string of lenght 100. Increase if needed.
If you have a need for other "delimiting characters" besides "-", "/", and " ", then just
modifiy the string "-/ " to contain also these characters.
Hope this helps / Lars-Åke
Marked As Answer byDharmesh Wednesday, September 15, 2010 2:26 PM
Reply
Quote

Dear Lars & Jeeped,


Thank you for all your precious time to respond my query. Both the devised formulas by
you gems work perfectly well.
Warm regards
Dharmesh

You might also like