数字转换文字_第1页
数字转换文字_第2页
数字转换文字_第3页
数字转换文字_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

此文章已于 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论