资源描述:
《excel 中如何将数字转换成英文》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、网上下载的代码1.创建一个模块: 在SHEET上,右键-》查看代码。选中“模块”-》插入模块。2.写代码:OptionExplicitDimStrNO(19)AsStringDimUnit(8)AsStringDimStrTens(9)AsStringPublicFunctionNumberToString(NumberAsDouble)AsString DimStrAsString,BeforePointAsString,AfterPointAsString,tmpStrAsString DimPointAsInteger DimnBitA
2、sInteger DimCurStringAsString DimnNumLenAsInteger DimTAsString CallInit Str=CStr(Round(Number,2)) 'Str=Number IfInStr(1,Str,".")=0Then BeforePoint=Str AfterPoint="" Else BeforePoint=Left(Str,InStr(1,Str,".")-1) T=Right(Str,Len(Str)-InStr(1,St
3、r,".")) IfLen(T)<2ThenAfterPoint=Val(T)*10 IfLen(T)=2ThenAfterPoint=Val(T) IfLen(T)>2ThenAfterPoint=Val(Left(T,2)) EndIf IfLen(BeforePoint)>12Then NumberToString="TooBig." ExitFunction EndIf Str="" DoWhileLen(BeforePoint)>0 nNumLen=Len(
4、BeforePoint) IfnNumLenMod3=0Then CurString=Left(BeforePoint,3) BeforePoint=Right(BeforePoint,nNumLen-3) Else CurString=Left(BeforePoint,(nNumLenMod3)) BeforePoint=Right(BeforePoint,nNumLen-(nNumLenMod3)) EndIf nBit=Len
5、(BeforePoint)/3 tmpStr=DecodeHundred(CurString) If(BeforePoint=String(Len(BeforePoint),"0")OrnBit=0)AndLen(CurString)=3Then IfCInt(Left(CurString,1))<>0AndCInt(Right(CurString,2))<>0Then 'tmpStr=Left(tmpStr,InStr(1,tmpStr,Unit(4))+Len(Unit(4)))&U
6、nit(8)&""&Right(tmpStr,Len(tmpStr)-(InStr(1,tmpStr,Unit(4))+Len(Unit(4)))) Else'IfCInt(Left(CurString,1))<>0AndCInt(Right(CurString,2))=0Then 'tmpStr=Unit(8)&""&tmpStr EndIf EndIf IfnBit=0Then Str=Trim(Str&""&tmpStr) Els
7、e Str=Trim(Str&""&tmpStr&""&Unit(nBit)) EndIf IfLeft(Str,3)=Unit(8)ThenStr=Trim(Right(Str,Len(Str)-3)) IfBeforePoint=String(Len(BeforePoint),"0")ThenExitDo 'Debug.PrintStr Loop BeforePoint=Str IfLen(AfterPoint)>0Then AfterPoint=Unit(6)&
8、""&DecodeHundred(AfterPoin