在excel中创建金额转中文大写函数需使用vba。具体步骤如下:1 按alt+f11打开vba编辑器,插入新
在excel中创建金额转中文大写函数需使用vba。具体步骤如下:1. 按alt+f11打开vba编辑器,插入新模块并输入代码;2. 函数可处理大数值和小数点,并根据需求优化和调试;3. 在excel中使用时,输入=converttochinese(数字)即可转换为中文大写金额。
在Excel中,将数字兑换成中文大写的金额是财务工作中常见的需求。使用自定义函数可以轻松实现这一转换。以下是实现这一功能的具体方法和步骤。
在Excel中创建一个自定义函数来将数字转换为中文大写金额,需要使用VBA(Visual Basic for Applications)。首先,按下Alt + F11打开VBA编辑器,然后插入一个新的模块,并输入以下代码:
Function ConvertToChinese(num As Double) As String Dim ChineseNum As Variant Dim ChineseUnit As Variant Dim strNum As String Dim strUnit As String Dim i As Integer Dim j As Integer Dim result As String ChineseNum = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖") ChineseUnit = Array("", "拾", "佰", "仟", "万", "亿") strNum = Format(num, "0.00") strNum = Replace(strNum, ".", "") For i = 1 To Len(strNum) j = Mid(strNum, i, 1) If j <> "0" Then result = result & ChineseNum(j) & ChineseUnit((Len(strNum) - i) Mod 4) ElseIf InStr(result, ChineseNum(0)) = 0 Or (i Mod 4 = 1 And i <> Len(strNum)) Then result = result & ChineseNum(0) End If If i Mod 4 = 0 And i <> Len(strNum) Then result = result & ChineseUnit(Int((Len(strNum) - i) / 4) + 4) End If Next i result = Replace(result, "零拾", "零") result = Replace(result, "零佰", "零") result = Replace(result, "零仟", "零") result = Replace(result, "零万", "万") result = Replace(result, "零亿", "亿") result = Replace(result, "零零", "零") If Left(result, 1) = "零" Then result = Mid(result, 2) If Right(result, 1) = "零" Then result = Left(result, Len(result) - 1) result = result & "元" If num - Int(num) > 0 Then strNum = Format(num - Int(num), "0.00") strNum = Mid(strNum, 3) If Mid(strNum, 1, 1) <> "0" Then result = result & ChineseNum(Mid(strNum, 1, 1)) & "角" End If If Mid(strNum, 2, 1) <> "0" Then result = result & ChineseNum(Mid(strNum, 2, 1)) & "分" End If End If If result = "元" Then result = "零元整" If Right(result, 1) = "元" Then result = result & "整" ConvertToChinese = resultEnd Function登录后复制
菜鸟下载发布此文仅为传递信息,不代表菜鸟下载认同其观点或证实其描述。
版权投诉请发邮件到 cn486com#outlook.com (把#改成@),我们会尽快处理
Copyright © 2019-2020 菜鸟下载(www.cn486.com).All Reserved | 备案号:湘ICP备2023003002号-8
本站资源均收集整理于互联网,其著作权归原作者所有,如有侵犯你的版权,请来信告知,我们将及时下架删除相应资源