Serving the Quantitative Finance Community

 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

Exel question

April 26th, 2006, 12:28 am

I have a cell with a string of digits of unspecified length, say 12345.I'd like to create a cell for every digit in the string to be in on it's own. So if A1 = 12345 then I want A2 = 1 A3 = 2 etc.Is there a function that can extract a digit in a position in a text string that is chosen by the user?
 
User avatar
irvingy
Posts: 0
Joined: July 14th, 2002, 3:00 am

Exel question

April 26th, 2006, 2:13 am

Mix len(), left(), right(). Maybe others have more elegant ways.QuoteOriginally posted by: brontosaurusI have a cell with a string of digits of unspecified length, say 12345.I'd like to create a cell for every digit in the string to be in on it's own. So if A1 = 12345 then I want A2 = 1 A3 = 2 etc.Is there a function that can extract a digit in a position in a text string that is chosen by the user?
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

Exel question

April 26th, 2006, 2:39 pm

hmmm, is there a function in VBA that does it? It seems pretty standard...
 
User avatar
gjlipman
Posts: 5
Joined: May 20th, 2002, 9:13 pm

Exel question

April 26th, 2006, 4:13 pm

Or you can use mid(number,position,1), eg A3=mid(a1,2,1)
 
User avatar
brontosaurus
Topic Author
Posts: 0
Joined: May 10th, 2004, 8:33 pm

Exel question

April 26th, 2006, 4:22 pm

yep, it works the way I need it - thank you.what does the 1 in the third parameter do?
 
User avatar
gjlipman
Posts: 5
Joined: May 20th, 2002, 9:13 pm

Exel question

April 26th, 2006, 4:46 pm

it tells it that it only wants a string one digit long
 
User avatar
darthtrader
Posts: 0
Joined: February 10th, 2004, 12:26 pm

Exel question

May 18th, 2006, 11:49 am

bit of a late answer - bit "brute force" but you can do the following...if you have the string in cell B2, in A3 have the following: =IF((LEN(B$2)-LEN(B$2)+A2)<LEN(B$2),(LEN(B$2)-LEN(B$2)+A2+1),"")...drag down the formula....in cell B3 have the following formula: =MID(B$2,A3,1)...drag down again....what you should get is a table that shows the character number and the corresponding string in the cell to the right....i.e. if i have 15687 in B2, in cells A3 to A7 i get 1,2,3,4,5 (number of characters), then in B3 to B7 i get 1,5,6,8,7. the solution is a bit ugly because you then get a blank cell in A8 followed by #VALUE! in the cells going down and also #VALUE1 in B8 downwards - about the best i can do though! EDIT...change the first formula to =IF(ISERROR(IF((LEN(B$2)-LEN(B$2)+A2)<LEN(B$2),(LEN(B$2)-LEN(B$2)+A2+1),"")),"",IF((LEN(B$2)-LEN(B$2)+A2)<LEN(B$2),(LEN(B$2)-LEN(B$2)+A2+1),""))...change the second one to =IF(ISERROR(MID(B$2,A3,1)),"",(MID(B$2,A3,1)))...i have now removed the unsightly errors AND created the most ugly/cumbersome formula ever...
Last edited by darthtrader on May 17th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
Rufus
Posts: 4
Joined: January 18th, 2002, 5:24 pm

Exel question

May 18th, 2006, 1:00 pm

You could use:=IF(COLUMN()-COLUMN($D$5)>LEN($D$5),"",MID($D$5,COLUMN()-COLUMN($D$5),1))where D5 holds your string and the formula is in columns starting E5.