LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default How to locate the first digit in a cell, explained

Several years ago, in a post that seems now closed to replies, Ron
Rosenfeld posted a solution to someone's request for a formula that
found the location of the first digit in each cell:



Array-entered formula:

MATCH(TRUE,ISNUMBER(--MID(A10,ROW(INDIRECT("1:"&LEN(A10))),1)),0)

To array-enter a formula, hold down <ctrl<shift while hitting <enter.
XL will place curly brackets {...} around the formula.


A colleague wanted to know how to do this and I tracked down the
post. But it didn't satisfy, quite (though it works perfectly); I
wanted to understand it, too. So I deconstructed it and wrote it up
for my colleague, then figured I would post it here as well for
posterity. So here is my explanation of the above formula.

The expression

INDIRECT("1:"&LEN(A10))

identifies the rows between the first and the one whose number is the
length of the text in A10. Why in the world would we want that?
Well, when we put ROW() around it and put it into an array formula, it
produces a series of integers, because ROW() returns an integer. So
that's a tricky way to get (in this case) the series {1;2;3;4;5;6}.
The formula reduces to:

{=MATCH(TRUE,ISNUMBER(--MID(A10,{1;2;3;4;5;6},1)),0)}

That's starting to make more sense.

The MID() of A10, for each element in the series 1-6, one character
long - that's just identifying the individual characters in turn. And
that's why the LEN(A10) was used to determine the series length. So
we reduce it to

{=MATCH(TRUE,ISNUMBER(--{"a"; "b"; "c"; "1"; "2"; "3"}),0)}

in the specific case where A10 holds "abc123". What's that "--" all
about?

Well, ISNUMBER("1") is false. But -"1" is -1, whereas -"a" produces a
#VALUE error; the double minus simply restores the original sign
(which in fact is unnecessary in this case because ISNUMBER(-1) is
also TRUE).

We're getting there.

{=MATCH(TRUE,{FALSE; FALSE; FALSE; TRUE; TRUE; TRUE},0)}

That says, find the first value in the series that matches TRUE and
return its position; the zero at the tail end I think signifies that
we require an exact match.

Got all that? This will be on the quiz... :-)

Peace,
--Carl

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to validate a cell to insert from 9 digit number to 13 digit number. ramulu via OfficeKB.com Excel Worksheet Functions 1 February 21st 07 02:32 PM
How to validate a cell to insert from 9 digit number to 13 digit number. ramulu Excel Worksheet Functions 1 February 21st 07 10:00 AM
Counting Formulas -- Re-explained MAB Excel Worksheet Functions 2 January 12th 06 09:18 PM
Color a single digit in a mult-digit number cell Phyllis Excel Discussion (Misc queries) 6 November 17th 05 12:46 AM
16 DIGIT NUMBERS IN CELL WITHOUT LAST DIGIT BEING A ZERO jnkell Excel Worksheet Functions 2 December 18th 04 07:13 PM


All times are GMT +1. The time now is 01:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"