用函数解决大写中文数字显示结果

下面是自定义函数的代码,其实它利用的就是[DBNUM2]
Private Function hhhh(i As Range)
If i.Value >= 1 Then
If Int(i) = i Or Round(i, 2) = Int(i) Then
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元整"
ElseIf Int(i * 10) = i * 10 Or Int(i) * 10 = Round(i, 2) * 10 Then
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "角整"
Else
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分"
End If
ElseIf i.Value < 1 And i.Value > 0 Then
If Int(i * 10) = i * 10 Then
hhhh = Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"
Else
hhhh = Application.WorksheetFunction.Text(Left(Right(i, 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "分"
End If
ElseIf i = o Then hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元"
Else
If Int(i) = i Then
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元"
ElseIf Int(i * 10) = i * 10 Or Round(Abs(i), 2) * 10 = Int(Abs(i)) * 10 Then
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"
Else
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "分" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分"
End If
End If
End Function
具体的操作是,按ALT+F11.打开VBE窗口,"插入"_"模块",将上面的这段代码复制过去
另存为"加载宏",文件名可以取"金额大小写转换"
以后要调用就在EXCEL里,"工具","加项宏","浏览",将它选中,双击即装入了.

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus