Suma in curirsive

内容

下面你会在 VBA 中找到一个现成的用户定义函数,它可以转换任何数字 从0到9 到它的文本表示,即在单词的数量。 使用前,必须将此功能添加到您的书籍中。 为了这:

  1. 按键盘快捷键 ALT + F11打开 Visual Basic 编辑器
  2. 通过菜单添加新的空模块 插入 - 模块
  3. 复制并粘贴此函数的文本:
函数 SUM(n As Double) As String Dim Nums1, Nums2, Nums3, Nums4 As Variant Nums1 = Array("", "one", "two", "three", "four", "five", "six", "七", "八", "九") Nums2 = Array("", "十", "二十", "三十", "四十", "五十", "六十", "七十", _ "八十", "九十") Nums3 = Array("", "一百", "二百", "三百", "四百", "五百", "六百", "七百", _ "八百", "九百") Nums4 = Array("", "一", "二", "三", "四", "五", "六", "七", "八", "九") Nums5 = Array("十 ", "十一", "十二", "十三", "十四", _ "十五", "十六", "十七", "十八", "十九") 如果 n < = 0 Then SU​​MWRITE = "zero" Exit Function End If '使用辅助函数将数字分成数字 Class ed = Class(n, 1) dec = Class(n, 2) sot = Class(n, 3) tys = Class (n, 4) dectys = Class(n , 5) sottys = Class(n, 6) mil = Class(n, 7) decmil= Class(n, 8) 'check millions Select Case decmil Case 1 mil_txt = Nums5(mil ) & "millions " GoTo www Case 2 To 9 decmil_txt = Nums2(decmil) End Select Case mil Case 1 mil_txt = Nums1(mil) & "million " Case 2, 3, 4 mil_txt = Nums1(mil) & "million " Case 5 To 20 mil_txt = Nums1(mil) & "millions " End Select www: sottys_txt = Nums3(sottys) ' check thousands 选择 Case dectys Case 1 tys_txt = Nums5(tys) & "thousands " GoTo eee Case 2 To 9 dectys_txt = Nums2(dectys) End Select Case tys Case 0 如果dectys > 0 Then tys_txt = Nums4(tys) & "thousands " Case 1 tys_txt = Nums4(tys) & "thousand " Case 2, 3, 4 tys_txt = Nums4(tys) & "thousands " Case 5 To 9 tys_txt = Nums4(tys) & "thousands " End Select If dectys = 0 And tys = 0 And sottys <> 0 Then sottys_txt = sottys_txt & "thousands" eee: sot_txt = Nums3(sot) '检查 tens Select Case dec Case 1 ed_txt = Nums5(ed) GoTo rrr Case 2 To 9 dec_txt = Nums2(dec) End Select ed_txt = Nums1 (ed) rrr: '用 SUM IN SPEECH = decmil_ txt & mil_txt & 形成最后一行sottys_txt & dectys_txt & tys_txt & sot_txt & dec_txt & ed_txt End Function ' 从数字中提取数字的辅助函数 Private Function Class(M, I) Class = Int(Int(M - (10 ^ I) * Int(M / ( 10 ^ I))) / 10 ^ (I - 1)) 结束函数    

保存文件(如果您有 Excel 2007 或 2010,则文件类型必须启用宏,即 xlsm 格式!)并返回 Excel。 现在您可以按照通常的方式将创建的函数插入工作表的任何单元格 - 通过函数向导(按钮 fx 在公式栏中,类别 用户自定义) 或简单地通过手动在单元格中键入它并使用金额作为参数指定单元格:

如果您需要在收到的文本中添加便士,那么您可以使用稍微复杂一点的构造:

 u3d 写入总和 (A3) & ” 擦。 “&TEXT((A3-INTEGER(A100))*00;”XNUMX″)&”警察。” 

u3d 写入总和 (A3) & ” 擦。 “&TEXT((A3-INT(A100))*00;”XNUMX″)&”警察。”

然后,例如,对于数字 35,15,函数的结果将看起来像“三十五卢布。 15 kop。”

 

  • 来自 PLEX 插件的更强大的功能版本,包含卢布和科比 / 英语
  • 什么是宏,在哪里插入宏代码,如何使用它们

 

发表评论