资源描述:
《EXCEL表格中将数字金额转换为英文.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Excel表格中如何将数字金额转换为英文(如B1列写162890元,自动转换为英文ONEHUNDREDSIXTYTWOTHOUSANDEIGHTHUNDREDNINETYDOLLARSANDNOCENTS)1、新建Excel表格2、按住“Alt+F11”打开VBA编辑器3、在VBA编辑器中单击菜单栏“插入”——模块4、在打开的模块中输入如下代码:OptionExplicitFunction数字转英文(ByValMyNumber)DimDollars,Cents,TempDimDecimalPlace,CountReDimPlace(9)AsStringPlace(
2、2)="Thousand"Place(3)="Million"Place(4)="Billion"Place(5)="Trillion"MyNumber=Trim(Str(MyNumber))DecimalPlace=InStr(MyNumber,".")IfDecimalPlace>0ThenCents=GetTens(Left(Mid(MyNumber,DecimalPlace+1)&_"00",2))MyNumber=Trim(Left(MyNumber,DecimalPlace-1))EndIfCount=1DoWhileMyNumber<>""Temp=
3、GetHundreds(Right(MyNumber,3))IfTemp<>""ThenDollars=Temp&Place(Count)&DollarsIfLen(MyNumber)>3ThenMyNumber=Left(MyNumber,Len(MyNumber)-3)ElseMyNumber=""EndIfCount=Count+1LoopSelectCaseDollarsCase""Dollars="NoDollars"Case"One"Dollars="OneDollar"CaseElseDollars=Dollars&"Dollars"EndSelec
4、tSelectCaseCentsCase""Cents="andNoCents"Case"One"Cents="andOneCent"CaseElseCents="and"&Cents&"Cents"EndSelect数字转英文=Dollars&CentsEndFunctionFunctionGetHundreds(ByValMyNumber)DimResultAsStringIfVal(MyNumber)=0ThenExitFunctionMyNumber=Right("000"&MyNumber,3)IfMid(MyNumber,1,1)<>"0"ThenRe
5、sult=GetDigit(Mid(MyNumber,1,1))&"Hundred"EndIfIfMid(MyNumber,2,1)<>"0"ThenResult=Result&GetTens(Mid(MyNumber,2))ElseResult=Result&GetDigit(Mid(MyNumber,3))EndIfGetHundreds=ResultEndFunctionFunctionGetTens(TensText)DimResultAsStringResult=""IfVal(Left(TensText,1))=1ThenSelectCaseVal(T
6、ensText)Case10:Result="Ten"Case11:Result="Eleven"Case12:Result="Twelve"Case13:Result="Thirteen"Case14:Result="Fourteen"Case15:Result="Fifteen"Case16:Result="Sixteen"Case17:Result="Seventeen"Case18:Result="Eighteen"Case19:Result="Nineteen"CaseElseEndSelectElseSelectCaseVal(Left(TensTex
7、t,1))Case2:Result="Twenty"Case3:Result="Thirty"Case4:Result="Forty"Case5:Result="Fifty"Case6:Result="Sixty"Case7:Result="Seventy"Case8:Result="Eighty"Case9:Result="Ninety"CaseElseEndSelectResult=Result&GetDigit_(Right(TensText,1))EndIfGetTens=ResultEndFunctionFunctionGetDigit(Digit)Se
8、lectC