全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
此文章已于 23:50:13 2016/3/12 发布到 醉资源博客数字转换为文字帐户醉资源博客If youve ever needed to display a number written out as text, you probably discovered that Excel does not offer such a function. When Excel fails to deliver, its often possible to correct the deficiency by using VBA. Heres a VBA function, named SPELLDOLLARS, that you can use in worksheet formulas.Excel examplesHere are some examples of SPELLDOLLARS.The VBA codeTo use this code, press Alt+F11 to activate Visual Basic Editor. Then choose Insert Module to insert a new VBA module. Copy the code and paste it into the new module.Function SPELLDOLLARS(cell) As Variant Returns a value, spelled out in words Dim Dollars As String, Cents As String Dim TextLen As Long, Pos As Long Dim Temp As String Dim iHundreds As Long, iTens As Long, iOnes As Long Dim Ones As Variant, Teens As Variant, Tens As Variant Dim Units(2 To 5) As String Dim bHit As Boolean, NegFlag As Boolean Is it a non-number or empty cell? If Not IsNumeric(cell) Or cell = “ Then SPELLDOLLARS = CVErr(xlErrValue) Exit Function End If Is it negative? If cell 15 Then SPELLDOLLARS = CVErr(xlErrNum) Exit Function End If Do the cents part Cents = Right(Dollars, 2) & “/100 Dollars” If cell = Pos - 2 Then bHit = False If TextLen = Pos Then iHundreds = Asc(Mid$(Dollars, TextLen - Pos + 1, 1) - 48 If iHundreds 0 Then Temp = Temp & “ “ & Ones(iHundreds) & “ Hundred” bHit = True End If End If iTens = 0 iOnes = 0 If TextLen = Pos - 1 Then iTens = Asc(Mid$(Dollars, TextLen - Pos + 2, 1) - 48 End If If TextLen = Pos - 2 Then iOnes = Asc(Mid$(Dollars, TextLen - Pos + 3, 1) - 48 End If If iTens = 1 Then Temp = Temp & “ “ & Teens(iOnes) bHit = True Else If iTens = 2 Then Temp = Temp & “ “ & Tens(iTens) bHit = True End If If iOnes 0 Then If iTens = 2 Then Temp = Temp & “-” Else Temp = Temp & “ “ End If Temp = Temp & Ones(iOnes) bHit = True End If End If If bHit And Pos 3 Then Temp = Temp & “ “ & Units(Pos 3) End If End If Next Pos SPELLDOLL
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广商延迟交房通知书
- 广州南海神庙开放通知书
- 广饶禁行申请通知书
- 库车供热停暖通知书
- 店面疫情期间通知书
- 廊职春节放假通知书
- 开发区无人机禁飞通知书
- 开封奥园交房通知书
- 引镇南留村停电通知书
- 当兵连长压通知书
- 安全生产巡检及整改方案表格
- 网络安装服务合同范本
- 2025小学一年级数学上册期中测试卷
- 《金色的草地》素养课件(第二课时)
- 2025吉林省国资委监管企业集中招考1214人联合考试笔试备考试题及答案解析
- 2025北京市公安局平谷分局第四季度招聘勤务辅警20人笔试考试参考试题及答案解析
- 2025至2030电动气动阀门定位器行业产业运行态势及投资规划深度研究报告
- 2025-2030智慧餐饮行业市场分析及投资前景研究报告
- 跑步体能训练讲座
- 别墅物业费代缴合同协议2025年规定
- 医疗废弃物相关知识培训课件
评论
0/150
提交评论