Excel 将金额转换成大写字母函数

本文介绍了一个使用VBA编写的函数,该函数能够将货币数值转换为中文大写形式,适用于财务报表中金额的规范化展示。通过将金额拆分为元、角、分,并利用Excel的Text函数进行转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Function CapsMoney(curMoney As Currency) As String '转换中文大写金额函数

Dim curMoney1 As Long

Dim i1 As Long '保存整数部分(元部分)

Dim i2 As Integer '保存十分位(角部分)

Dim i3 As Integer '保存百分位(分部分)

Dim s1 As String, s2 As String, s3 As String '保存转换后的字符串

curMoney1 = Round(curMoney * 100) '将金额扩大100倍,并进行四舍五入

i1 = Int(curMoney1 / 100) '获取元部分

i2 = Int(curMoney1 / 10) - i1 * 10 '获取角部分

i3 = curMoney1 - i1 * 100 - i2 * 10 '获取分部分

s1 = Application.WorksheetFunction.Text(i1, "[dbnum2]")

'将元部分转为中文大写

s2 = Application.WorksheetFunction.Text(i2, "[dbnum2]")

'将角部分转为中文大写

s3 = Application.WorksheetFunction.Text(i3, "[dbnum2]")

'将分部分转为中文大写

s1 = s1 & "元" '整数部分

If i3 <> 0 And i2 <> 0 Then '分和角都不为0

s1 = s1 & s2 & "角" & s3 & "分"

If i1 = 0 Then '元部分为0

s1 = s2 & "角" & s3 & "分"

End If

End If

If i3 = 0 And i2 <> 0 Then '分为0,角不为0

s1 = s1 & s2 & "角整"

If i1 = 0 Then '元部分为0

s1 = s2 & "角整"

End If

End If

If i3 <> 0 And i2 = 0 Then '分不为0,角为0

s1 = s1 & s2 & s3 & "分"

If i1 = 0 Then '元为0

s1 = s3 & "分"

End If

End If

If Right(s1, 1) = "元" Then s1 = s1 & "整" '为"元"后加上一个"整"字

CapsMoney = s1

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小蚂蚁_CrkRes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值