VBA 如何将数字转换为中文大写
答案:3 悬赏:40 手机版
解决时间 2021-11-15 20:24
- 提问者网友:酱爆肉
- 2021-11-15 09:20
VBA 如何将数字转换为中文大写
最佳答案
- 五星知识达人网友:一秋
- 2021-11-15 10:57
使用Text函数即可。
如将78转换为七十八:=Text(78,"[dbnum1]")
如将78转换为柒拾捌:=Text(78,"[dbnum2]")
数字可以为单元格引用,也就是把78改为A1形式。
如将78转换为七十八:=Text(78,"[dbnum1]")
如将78转换为柒拾捌:=Text(78,"[dbnum2]")
数字可以为单元格引用,也就是把78改为A1形式。
全部回答
- 1楼网友:孤独入客枕
- 2021-11-15 12:56
楼主说的不是很具体,下面的内容请参考:
读取单元格的值,求出长度,利用循环逐个对单元格内的数字使用SELECT CASE语句 进行替换。
读取单元格的值,求出长度,利用循环逐个对单元格内的数字使用SELECT CASE语句 进行替换。
- 2楼网友:低音帝王
- 2021-11-15 11:19
Public Function 中文大写(数字 As Currency) As String
Dim a As Variant, b As Integer, c As Integer
Dim q(1 To 9) As String, s1 As Variant
q(1) = "壹": q(2) = "贰": q(3) = "叁": q(4) = "肆"
q(5) = "伍": q(6) = "陆": q(7) = "柒": q(8) = "捌": q(9) = "玖"
a = Int(数字)
b = Val(Mid(Str(数字), InStr(1, Str(数字), ".") + 1, 1))
c = Val(Right(Application.Text(Str(数字 * 100), "0"), 1))
s1 = Application.Text(a, "[dbnum2]")
If a = 0 Then
If b = 0 Then
If c = 0 Then
中文大写 = ""
Exit Function
Else
中文大写 = q(c) & "分"
Exit Function
End If
ElseIf c = 0 Then
中文大写 = q(b) & "角整"
Exit Function
Else
中文大写 = q(b) & "角" & q(c) & "分"
Exit Function
End If
ElseIf b = 0 Then
If c = 0 Then
中文大写 = s1 & "元整"
Exit Function
Else
中文大写 = s1 & "元零" & q(c) & "分"
Exit Function
End If
ElseIf c = 0 Then
中文大写 = s1 & "元" & q(b) & "角整"
Exit Function
Else
中文大写 = s1 & "元" & q(b) & "角" & q(c) & "分"
Exit Function
End If
End Function
Dim a As Variant, b As Integer, c As Integer
Dim q(1 To 9) As String, s1 As Variant
q(1) = "壹": q(2) = "贰": q(3) = "叁": q(4) = "肆"
q(5) = "伍": q(6) = "陆": q(7) = "柒": q(8) = "捌": q(9) = "玖"
a = Int(数字)
b = Val(Mid(Str(数字), InStr(1, Str(数字), ".") + 1, 1))
c = Val(Right(Application.Text(Str(数字 * 100), "0"), 1))
s1 = Application.Text(a, "[dbnum2]")
If a = 0 Then
If b = 0 Then
If c = 0 Then
中文大写 = ""
Exit Function
Else
中文大写 = q(c) & "分"
Exit Function
End If
ElseIf c = 0 Then
中文大写 = q(b) & "角整"
Exit Function
Else
中文大写 = q(b) & "角" & q(c) & "分"
Exit Function
End If
ElseIf b = 0 Then
If c = 0 Then
中文大写 = s1 & "元整"
Exit Function
Else
中文大写 = s1 & "元零" & q(c) & "分"
Exit Function
End If
ElseIf c = 0 Then
中文大写 = s1 & "元" & q(b) & "角整"
Exit Function
Else
中文大写 = s1 & "元" & q(b) & "角" & q(c) & "分"
Exit Function
End If
End Function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯