金额大小写转换宏编程

发布时间:2015-05-14 11:18:49   来源:文档文库   
字号:

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

本文来源:https://www.2haoxitong.net/k/doc/0f7885ac2af90242a895e5fd.html

《金额大小写转换宏编程.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式