您好,欢迎访问三七文档
EXCEL中将数字转换为人民币大写鉴于EXCEL本身提供将数字转换为大写表示的功能根本不能正常应用在实际投标或财务应用之中,所以要自己建设,暂时找到了三种实现途径,经过测试均功能正常。方法1,通过在EXCEL表格框(例如在“B1”单元)中直接输入以下公式:=IF(A10,金额为负无效,(IF(OR(A1=0,A1=),(人民币)零元,IF(A11,(人民币),TEXT(INT(A1),[dbnum2](人民币)G/通用格式)&元))))&IF((INT(A1*10)-INT(A1)*10)=0,IF(INT(A1*100)-INT(A1*10)*10=0,,零),(TEXT(INT(A1*10)-INT(A1)*10,[dbnum2])&角))&IF((INT(A1*100)-INT(A1*10)*10)=0,整,TEXT((INT(A1*100)-INT(A1*10)*10),[dbnum2])&分)然后在“A1”中输入数字,就可看到效果。方法2,通过VBA(宏)输入转换公式:点击菜单“工具”-“宏”-“VisualBasic编辑器”,在编辑器窗口中,点击菜单“插入”-“模块”,在出现的窗口中输入以下内容:Functiondaxie(ByValNum)'人民币中文大写函数Application.VolatileTruePlace=分角元拾佰仟万拾佰仟亿拾佰仟万Dn=壹贰叁肆伍陆柒捌玖D1=整零元零零零万零零零亿零零零万IfNum0ThenFuHao=(负)Num=Format(Abs(Num),###0.00)*100IfNum999999999999999#Then:daxie=数字超出转换范围!!:ExitFunctionIfNum=0Then:daxie=零元零分:ExitFunctionNumA=Trim(Str(Num))NumLen=Len(NumA)ForJ=NumLenTo1Step-1'数字转换过程temp=Val(Mid(NumA,NumLen-J+1,1))Iftemp0Then'非零数字转换NumC=NumC&Mid(Dn,temp,1)&Mid(Place,J,1)Else'数字零的转换IfRight(NumC,1)零ThenNumC=NumC&Mid(D1,J,1)ElseSelectCaseJ'特殊数位转换Case1NumC=Left(NumC,Len(NumC)-1)&Mid(D1,J,1)Case3,11NumC=Left(NumC,Len(NumC)-1)&Mid(D1,J,1)&零Case7IfMid(NumC,Len(NumC)-1,1)亿ThenNumC=Left(NumC,Len(NumC)-1)&Mid(D1,J,1)&零EndIfCaseElseEndSelectEndIfEndIfNextdaxie=(人民币)&FuHao&Trim(NumC)EndFunction然后切换回excel,在“A2”单元中输入数字,在“B2”单元中输入:“=DaXie(A2)”,就可看到效果。方法3,同样是通过VBA公式,方法同上,公式如下:Functiondaxie1(moneyAsString)AsString'DimxAsString,yAsStringConstzimu=.sbqwsbqysbqwsbq'定义位置代码Constletter=0123456789sbqwy.zjf'定义汉字缩写Constupcase=零壹贰叁肆伍陆柒捌玖拾佰仟萬億圆整角分'定义大写汉字DimtempAsStringtemp=moneyIfInStr(temp,.)0Thentemp=Left(temp,InStr(temp,.)-1)IfLen(temp)16ThenMsgBox数目太大,无法换算!请输入一亿亿以下的数字,64,错误提示:ExitFunction'只能转换一亿亿元以下数目的货币!x=Format(money,0.00)'格式化货币y=Fori=1ToLen(x)-3y=y&Mid(x,i,1)&Mid(zimu,Len(x)-2-i,1)NextIfRight(x,3)=.00Theny=y&z'***元整Elsey=y&Left(Right(x,2),1)&j&Right(x,1)&f'*元*角*分EndIfy=Replace(y,0q,0)'避免零千(如:40200肆萬零千零贰佰)y=Replace(y,0b,0)'避免零百(如:41000肆萬壹千零佰)y=Replace(y,0s,0)'避免零十(如:204贰佰零拾零肆)DoWhileyReplace(y,00,0)y=Replace(y,00,0)'避免双零(如:1004壹仟零零肆)Loopy=Replace(y,0y,y)'避免零億(如:210億贰佰壹十零億)y=Replace(y,0w,w)'避免零萬(如:210萬贰佰壹十零萬)y=IIf(Len(x)=5AndLeft(y,1)=1,Right(y,Len(y)-1),y)'避免壹十(如:14壹拾肆;10壹拾)y=IIf(Len(x)=4,Replace(y,0.,),Replace(y,0.,.))'避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)Fori=1To19y=Replace(y,Mid(letter,i,1),Mid(upcase,i,1))'大写汉字Nextdaxie1=(人民币)&yEndFunction切换回excel,在“A3”单元中输入数字,在“B3”单元中输入:“=DaXie1(A3)”,就可看到效果。
本文标题:金额小写转大写
链接地址:https://www.777doc.com/doc-1968840 .html