友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
狗狗书籍 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

Excel word ppt office使用技巧大全(DOC格式)-第50章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!




金额的数字可以转化为英文大写吗如: US1;234。00 US Dollars One Thousand Two Hundred  

And Thirty Four Only。    

===   



Current Special! plete Excel Excel Training Course for Excel 97 Excel 2003;  

only 145。00。 59。95 Instant Buy/Download Includes 2 Excel VBA Courses  

(20 lessons and 5 Workbook Downloads in each)   



Back to: Excel Custom Function/Formulas。 Got any Excel/VBA Questions?  

Free Excel Help  



See Also: Convert Numbers to Words/Text  



Here is a very popular bit of code from Microsoft that will convert any currency  

amount in a cell to English words。 All code and text from below here is the  

work of Microsoft。 Summary This article shows you how to create a sample;  

user…defined function named ConvertCurrencyToEnglish() to convert a numeric  

value to an English word representation。 For example; the function will return the  

following words for the number 1234。56: One Thousand Two Hundred Thirty  

Four Dollars And Fifty Six Cents The Function Wizard can also be used to enter  

a custom function in a worksheet。 To use the Function Wizard; follow these steps:  

1。 Click the Function Wizard button; and select User Defined under Function  

Category。 2。 Select ConvertCurrencyToEnglish; and enter your number or cell  

reference。 3。 Click Finish To Create the Sample Functions  1。 Insert a module  

sheet into a workbook。 To do this in Microsoft Excel 97 or Microsoft Excel 98; point  

to Macro on the Tools menu; and then click Visual Basic Editor。 In the Visual Basic  

Editor; click Module on the Insert menu。 In Microsoft Excel   



                                              CXCI  


…………………………………………………………Page 192……………………………………………………………

                               Excel_word_ppt_使用技巧大全(完全版)  



5。0 or 7。0; point to Macro on the Insert menu and click Module。 2。 Type the  

following code into the module sheet。    



Function ConvertCurrencyToEnglish (ByVal MyNumber)   

Dim Temp   

Dim Dollars; Cents   

Dim DecimalPlace; Count   

ReDim Place(9) As String   

Place(2) = 〃 Thousand 〃   

Place(3) = 〃 Million 〃   

Place(4) = 〃 Billion 〃   

Place(5) = 〃 Trillion 〃   

' Convert MyNumber to a string; trimming extra spaces。   

MyNumber = Trim(Str(MyNumber))   

' Find decimal place。   

DecimalPlace = InStr(MyNumber; 〃。〃)   

' If we find decimal place。。。   

If DecimalPlace 》 0 Then   

' Convert cents   

Temp = Left(Mid(MyNumber; DecimalPlace + 1) & 〃00〃; 2)   

Cents = ConvertTens(Temp)   

' Strip off cents from remainder to convert。   

MyNumber = Trim(Left(MyNumber; DecimalPlace 1))   

End If   

Count = 1   

Do While MyNumber  〃〃   

' Convert last 3 digits of MyNumber to English dollars。   

Temp = ConvertHundreds(Right(MyNumber; 3))   

If Temp  〃〃 Then Dollars = Temp & Place(Count) & Dollars   

If Len(MyNumber) 》 3 Then   

' Remove last 3 converted digits from MyNumber。   

MyNumber = Left(MyNumber; Len(MyNumber) 3)   

Else   

MyNumber = 〃〃   

End If   

Count = Count + 1   

Loop   



                                          CXCII  


…………………………………………………………Page 193……………………………………………………………

                               Excel_word_ppt_使用技巧大全(完全版)  



' Clean up dollars。   

Select Case Dollars   

Case 〃〃   

Dollars = 〃No Dollars〃   

Case 〃One〃   

Dollars = 〃One Dollar〃   

Case Else   

Dollars = Dollars & 〃 Dollars〃   

End Select   

' Clean up cents。   

Select Case Cents   

Case 〃〃   

Cents = 〃 And No Cents〃   

Case 〃One〃   

Cents = 〃 And One Cent〃   

Case Else   

Cents = 〃 And 〃 & Cents & 〃 Cents〃   

End Select   

ConvertCurrencyToEnglish = Dollars & Cents   

End Function   

Private Function ConvertHundreds (ByVal MyNumber)   

Dim Result As String   

' Exit if there is nothing to convert。   

If Val(MyNumber) = 0 Then Exit Function   

' Append leading zeros to number。   

MyNumber = Right(〃000〃 & MyNumber; 3)   

' Do we have a hundreds place digit to convert?   

If Left(MyNumber; 1)  〃0〃 Then   

Result = ConvertDigit(Left(MyNumber; 1)) & 〃 Hundred 〃   

End If   

' Do we have a tens place digit to convert?   

If Mid(MyNumber; 2; 1)  〃0〃 Then   

Result = Result & ConvertTens(Mid(MyNumber; 2))   

Else   



                                          CXCIII  


…………………………………………………………Page 194……………………………………………………………

                               Excel_word_ppt_使用技巧大全(完全版)  



' If not; then convert the ones place digit。   

Result = Result & ConvertDigit(Mid(MyNumber; 3))   

End If   

ConvertHundreds = Trim(Result)   

End Function   

Private Function ConvertTens (ByVal MyTens)   

Dim Result As String   

' Is value between 10 and 19?   

If Val(Left(MyTens; 1)) = 1 Then   

Select Case Val(MyTens)   

Case 10: Result = 〃Ten〃   

Case 11: Result = 〃Eleven〃   

Case 12: Result = 〃Twelve〃   

Case 13: Result = 〃Thirteen〃   

Case 14: Result = 〃Fourteen〃   

Case 15: Result = 〃Fifteen〃   

Case 16: Result = 〃Sixteen〃   

Case 17: Result = 〃Seventeen〃   

Case 18: Result = 〃Eighteen〃   

Case 19: Result = 〃Nineteen〃   

Case Else   

End Select   

Else   

' 。。 otherwise it's between 20 and 99。   

Select Case Val(Left(MyTens; 1))   

Case 2: Result = 〃Twenty 〃   

Case 3: Result = 〃Thirty 〃   

Case 4: Result = 〃Forty 〃   

Case 5: Result = 〃Fifty 〃   

Case 6: Result = 〃Sixty 〃   

Case 7: Result = 〃Seventy 〃   

Case 8: Result = 〃Eighty 〃   

Case 9: Result = 〃Ninety 〃   

Case Else   

End Select   

' Convert ones place digit。   

Result = Result & ConvertDigit(Right(MyTens; 1))   

End If   



                                         CXCIV  


…………………………………………………………Page 195……………………………………………………………

                                Excel_word_ppt_使用技巧大全(完全版)  



ConvertTens = Result   

End Function   

Private Function ConvertDigit (ByVal MyDigit)   

Select Case Val(MyDigit)   

Case 1: ConvertDigit = 〃One〃   

Case 2: ConvertDigit = 〃Two〃   

Case 3: ConvertDigit 
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!