数字转换文字.doc

数字转换文字.doc

ID:56707807

大小:149.00 KB

页数:4页

时间:2020-07-05

数字转换文字.doc_第1页
数字转换文字.doc_第2页
数字转换文字.doc_第3页
数字转换文字.doc_第4页
资源描述:

《数字转换文字.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、此文章已于23:50:132016/3/12发布到醉资源博客数字转换为文字帐户醉资源博客Ifyou’veeverneededtodisplayanumberwrittenoutastext,youprobablydiscoveredthatExceldoesnotoffersuchafunction.WhenExcelfailstodeliver,it’softenpossibletocorrectthedeficiencybyusingVBA.Here’saVBAfunction,namedSPELLDOLLARS,thatyoucanuseinworksheetformulas.Excel

2、examplesHerearesomeexamplesofSPELLDOLLARS.TheVBAcodeTousethiscode,pressAlt+F11toactivateVisualBasicEditor.ThenchooseInsert→ModuletoinsertanewVBAmodule.Copythecodeandpasteitintothenewmodule.FunctionSPELLDOLLARS(cell)AsVariant‘Returnsavalue,spelledoutinwordsDimDollarsAsString,CentsAsStringDimTextLenAs

3、Long,PosAsLongDimTempAsStringDimiHundredsAsLong,iTensAsLong,iOnesAsLongDimOnesAsVariant,TeensAsVariant,TensAsVariantDimUnits(2To5)AsStringDimbHitAsBoolean,NegFlagAsBoolean‘Isitanon-numberoremptycell?IfNotIsNumeric(cell)Orcell=““ThenSPELLDOLLARS=CVErr(xlErrValue)ExitFunctionEndIf‘Isitnegative?Ifcell<

4、0ThenNegFlag=Truecell=Abs(cell)EndIfDollars=Format(cell,“###0.00”)TextLen=Len(Dollars)-3‘Isittoolarge?IfTextLen>15ThenSPELLDOLLARS=CVErr(xlErrNum)ExitFunctionEndIf‘DothecentspartCents=Right(Dollars,2)&“/100Dollars”Ifcell<1ThenSPELLDOLLARS=CentsExitFunctionEndIfDollars=Left(Dollars,TextLen)Ones=Array

5、(““,“One”,“Two”,“Three”,“Four”,_“Five”,“Six”,“Seven”,“Eight”,“Nine”)Teens=Array(“Ten”,“Eleven”,“Twelve”,“Thirteen”,“Fourteen”,_“Fifteen”,“Sixteen”,“Seventeen”,“Eighteen”,“Nineteen”)Tens=Array(““,““,“Twenty”,“Thirty”,“Forty”,“Fifty”,_“Sixty”,“Seventy”,“Eighty”,“Ninety”)Units(2)=“Thousand”Units(3)=“Mi

6、llion”Units(4)=“Billion”Units(5)=“Trillion”Temp=““ForPos=15To3Step-3IfTextLen>=Pos-2ThenbHit=FalseIfTextLen>=PosTheniHundreds=Asc(Mid$(Dollars,TextLen-Pos+1,1))-48IfiHundreds>0ThenTemp=Temp&““&Ones(iHundreds)&“Hundred”bHit=TrueEndIfEndIfiTens=0iOnes=0IfTextLen>=Pos-1TheniTens=Asc(Mid$(Dollars,TextLe

7、n-Pos+2,1))-48EndIfIfTextLen>=Pos-2TheniOnes=Asc(Mid$(Dollars,TextLen-Pos+3,1))-48EndIfIfiTens=1ThenTemp=Temp&““&Teens(iOnes)bHit=TrueElseIfiTens>=2ThenTemp=Temp&““&Tens(iTens)bHit=TrueEndIfIfiOnes>0T

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。