将Excel值转换为单词(英文)

时间:2013-02-25 11:12:09

标签: excel excel-2007 excel-formula excel-2010

我发现这个公式可以将金额转化为单词,但它不能100%起作用。每当金额以20,30,40等结尾时,它就会出错。例如1020将给出错误,但1019和1021将正常工作。我试图自己解决这个问题,但没有运气。它必须是公式(它与之接口的软件(Google Docs)无法处理VBA脚本。

这是公式:

=IF(H53<10^12,
    IF(INT(H53/10^9)>0,
        IF(INT(H53/10^11)>0,
            INDEX(
                {"One ","Two ","Three","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(INT(H53/10^11),{1,2,3,4,5,6,7,8,9})
            )&"Hundred ",
        "")&
        IF(MOD(INT(H53/10^9),100)<20,
            INDEX(
                {"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ",
                "Eleven ","Twelve","Thirteen","Fourteen ","Fifteen","Sixteen","Seventeen","Eighteen ","Nineteen"},
                MATCH(MOD(INT(H53/10^9),100),{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19})
            ),
            INDEX(
                {"","Twenty ","Thirty ","Fourty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "}, 
                MATCH(INT(MOD(INT(H53/10^9),100)/10),{1,2,3,4,5,6,7,8,9})
            )&
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "}, 
                MATCH(MOD(INT(H53/10^9),10),{1,2,3,4,5,6,7,8,9})
            )
        )&" Billion  ",
        ""
    )&
    IF(MOD(INT(H53/10^6),10^3)>0,
        IF(INT(MOD(INT(H53/10^6),10^3)/100)>0,
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(INT(MOD(INT(H53/10^6),10^3)/100),{1,2,3,4,5,6,7,8,9})
            )&"Hundred ",
        "")&
        IF(MOD(INT(H53/10^6),100)<20,
            INDEX(
                {"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ",
                "Eleven ","Twelve","Thirteen","Fourteen ","Fifteen ","Sixteen","Seventeen","Eighteen ","Nineteen"},
                MATCH(MOD(INT(H53/10^6),100),{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19})
            ),
            INDEX(
                {"","Twenty ","Thirty ","Fourty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "},
                MATCH(INT(MOD(INT(H53/10^6),100)/10),{1,2,3,4,5,6,7,8,9})
            )&
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "}, 
                MATCH(MOD(INT(H53/10^6),10),{1,2,3,4,5,6,7,8,9})
            )
        )&" Million  ",
        ""
    )&
    IF(MOD(INT(H53/10^3),10^3)>0,
        IF(INT(MOD(INT(H53/10^3),10^3)/100)>0,
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(INT(MOD(INT(H53/10^3),10^3)/100),{1,2,3,4,5,6,7,8,9})
            )&"Hundred ",
        "")&
        IF(MOD(INT(H53/10^3),100)<20,
            INDEX(
                {"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ",
                "Eleven ","Twelve","Thirteen","Fourteen ","Fifteen ","Sixteen","Seventeen","Eighteen ","Nineteen"},
                MATCH(MOD(INT(H53/10^3),100),{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19})
            ),
            INDEX(
                {"","Twenty ","Thirty ","Fourty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "},
                MATCH(INT(MOD(INT(H53/10^3),100)/10),{1,2,3,4,5,6,7,8,9})
            )&
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(MOD(INT(H53/10^3),10),{1,2,3,4,5,6,7,8,9})
            )
        )&" Thousand  ",
        ""
    )&
    IF(MOD(MOD(H53,10^4),10^3)>0,
        IF(INT(MOD(MOD(H53,10^4),10^3)/100)>0,
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(INT(MOD(MOD(H53,10^4),10^3)/100),{1,2,3,4,5,6,7,8,9})
            )&"Hundred ",
            ""
        )&
        IF(MOD(MOD(MOD(H53,10^4),10^3),100)<20,
            INDEX(
                {"","One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine ","Ten ",
                "Eleven ","Twelve","Thirteen","Fourteen ","Fifteen ","Sixteen","Seventeen","Eighteen ","Nineteen"},
                MATCH(MOD(MOD(MOD(H53,10^4),10^3),100),{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19})
            ),
            INDEX(
                {"","Twenty ","Thirty ","Fourty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "},
                MATCH(INT(MOD(MOD(MOD(H53,10^4),10^3),100)/10),{1,2,3,4,5,6,7,8,9})
            )&
            INDEX(
                {"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
                MATCH(MOD(MOD(MOD(H53,10^4),10^3),10),{1,2,3,4,5,6,7,8,9})
            )
        ),
        ""
    ),
    ""
) & " Rands"

1 个答案:

答案 0 :(得分:3)

问题出在最后一部分:

 INDEX({"One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
     MATCH(MOD(MOD(MOD(H53,10^4),10^3),10),{1,2,3,4,5,6,7,8,9})

MOD(MOD(MOD(H53,10^4),10^3),10)将返回0,这在1-9中找不到。

因此,上述行应修改为:

 INDEX({"", "One ","Two ","Three ","Four ","Five ","Six ","Seven ","Eight ","Nine "},
     MATCH(MOD(MOD(MOD(H53,10^4),10^3),10),{0, 1,2,3,4,5,6,7,8,9})

这个问题在公式的其他方面也存在。

所有内容都固定在这个完整的公式中(它还添加了一些不一致的空格):

=IF(B1<10^12,
 IF(INT(B1/10^9)>0,
  IF(INT(B1/10^11)>0,
   INDEX(
    {"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(INT(B1/10^11),{1;2;3;4;5;6;7;8;9})
   )&"Hundred ",
  "")&
  IF(MOD(INT(B1/10^9),100)<20,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine ";"Ten ";"Eleven ";"Twelve ";"Thirteen ";"Fourteen ";"Fifteen ";"Sixteen ";"Seventeen ";"Eighteen ";"Nineteen "},
    MATCH(MOD(INT(B1/10^9),100),{0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19})
   ),
   INDEX(
    {"";"Twenty ";"Thirty ";"Fourty ";"Fifty ";"Sixty ";"Seventy ";"Eighty ";"Ninety "},
    MATCH(INT(MOD(INT(B1/10^9),100)/10),{1;2;3;4;5;6;7;8;9})
   )&
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(MOD(INT(B1/10^9),10),{0;1;2;3;4;5;6;7;8;9})
   )
  )&" Billion  ",
  ""
 )&
 IF(MOD(INT(B1/10^6),10^3)>0,
  IF(INT(MOD(INT(B1/10^6),10^3)/100)>0,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(INT(MOD(INT(B1/10^6),10^3)/100),{0;1;2;3;4;5;6;7;8;9})
   )&"Hundred ",
  "")&
  IF(MOD(INT(B1/10^6),100)<20,
   INDEX(
   {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine ";"Ten ";"Eleven ";"Twelve ";"Thirteen ";"Fourteen ";"Fifteen ";"Sixteen ";"Seventeen ";"Eighteen ";"Nineteen "},
    MATCH(MOD(INT(B1/10^6),100),{0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19})
   ),
   INDEX(
    {"";"Twenty ";"Thirty ";"Fourty ";"Fifty ";"Sixty ";"Seventy ";"Eighty ";"Ninety "},
    MATCH(INT(MOD(INT(B1/10^6),100)/10),{1;2;3;4;5;6;7;8;9})
   )&
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(MOD(INT(B1/10^6),10),{0;1;2;3;4;5;6;7;8;9})
   )
  )&" Million  ",
  ""
 )&
 IF(MOD(INT(B1/10^3),10^3)>0,
  IF(INT(MOD(INT(B1/10^3),10^3)/100)>0,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(INT(MOD(INT(B1/10^3),10^3)/100),{0;1;2;3;4;5;6;7;8;9})
   )&"Hundred ",
  "")&
  IF(MOD(INT(B1/10^3),100)<20,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine ";"Ten ";"Eleven ";"Twelve ";"Thirteen ";"Fourteen ";"Fifteen ";"Sixteen ";"Seventeen ";"Eighteen ";"Nineteen "},
    MATCH(MOD(INT(B1/10^3),100),{0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19})
   ),
   INDEX(
    {"";"Twenty ";"Thirty ";"Fourty ";"Fifty ";"Sixty ";"Seventy ";"Eighty ";"Ninety "},
    MATCH(INT(MOD(INT(B1/10^3),100)/10),{1;2;3;4;5;6;7;8;9})
   )&
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(MOD(INT(B1/10^3),10),{0;1;2;3;4;5;6;7;8;9})
   )
  )&" Thousand  ",
  ""
 )&
 IF(MOD(MOD(B1,10^4),10^3)>0,
  IF(INT(MOD(MOD(B1,10^4),10^3)/100)>0,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(INT(MOD(MOD(B1,10^4),10^3)/100),{0;1;2;3;4;5;6;7;8;9})
   )&"Hundred ",
   ""
  )&
  IF(MOD(MOD(MOD(B1,10^4),10^3),100)<20,
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine ";"Ten ";"Eleven ";"Twelve ";"Thirteen ";"Fourteen ";"Fifteen ";"Sixteen ";"Seventeen ";"Eighteen ";"Nineteen "},
    MATCH(MOD(MOD(MOD(B1,10^4),10^3),100),{0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19})
   ),
   INDEX(
    {"";"Twenty ";"Thirty ";"Fourty ";"Fifty ";"Sixty ";"Seventy ";"Eighty ";"Ninety "},
    MATCH(INT(MOD(MOD(MOD(B1,10^4),10^3),100)/10),{1;2;3;4;5;6;7;8;9})
   )&
   INDEX(
    {"";"One ";"Two ";"Three ";"Four ";"Five ";"Six ";"Seven ";"Eight ";"Nine "},
    MATCH(MOD(MOD(MOD(B1,10^4),10^3),10),{0;1;2;3;4;5;6;7;8;9})
   )
  ),
  ""
 ),
 ""
) & " Rands"