0

i have data from a csv file. One Column contains Text like "0.2.11" which i need to reformat to "00.02.0011", the leading zeroes and the length of the dot seperated parts are crucial. These are no dates, just random Numbers. How can i reformat those?

Thanks.

1
  • Could you use a formula like: ="0"&REPLACE(REPLACE(A1,3,0,"0"),6,0,"00")? Commented May 14, 2012 at 11:53

2 Answers 2

1

I know that this is an insanely long formula, but I believe it will do what you're looking for:

=IF(LEN(IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))=2,IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)),"0"&IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))&"."&IF(RIGHT(MID(A1,FIND(".",A1)+1,2))<>".",MID(A1,FIND(".",A1)+1,2),"0"&LEFT(MID(A1,FIND(".",A1)+1,2),1))&"."&IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=4,RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=3,"0"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=2,"00"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),"000"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))))

It's probably long enough that you'd have to save this in one of the new Excel formats like .xlsx or .xlsm for it to save. If you have trouble with it let me know, I also have the formula broken out into several cells (or steps) if you need it that way.

Sign up to request clarification or add additional context in comments.

Comments

0

There is a shorter (but still ugly) Excel formula using TEXT function for formatting:

=TEXT(MID(A1,1,FIND(".",A1)-1),"00") &"."& TEXT(MID(A1,FIND(".",A1)+1,FIND(".",A1,FIND(".",A1)+1)-FIND(".",A1)-1),"00") &"."& TEXT(RIGHT(A1,LEN(A1)-FIND(".",A1,FIND(".",A1)+1)),"0000")

I would like to point out there are other methods of solving the same problem. If you have lots of big csv files you might consider preprocessing before importing into Excel. For example, doing the same job in awk is trivial:

BEGIN {
    while(getline < "e.csv") {
        split($1,a,".");
        printf("%02d.%02d.%04d\n",a[1],a[2],a[3]);
    }
}

Gawk works well with Windows. After installing, you can run it on the Windows or PowerShell command line as .\awk -f x.awk where x.awk is the above code in a text file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.