把以下代码贴在模块中,在自定义函数中直接调用. Function drmb(yuan) If IsNumeric(yuan) = False Then
drmb = "无效数值"
Exit Function
End If drmb = ""
If yuan < 0 Then
drmb = "负"
End If rmb1 = Application.WorksheetFunction.Round(Abs(yuan), 2) aa = Int(rmb1) aaa = Round((rmb1 - aa) * 100) bb = Int(aaa / 10) cc = aaa Mod 10 rmb_s = Len(Format(aa, "###0")) If rmb_s > 16 Then
drmb = "数值过大"
Exit Function
End If daa = Application.WorksheetFunction.Text(aa, "[dbnum2]") dbb = Application.WorksheetFunction.Text(bb, "[dbnum2]") dcc = Application.WorksheetFunction.Text(cc, "[dbnum2]")
If aa <> 0 Then
drmb = drmb & daa & "元"
End If
If Trim(rmb1) = 0 Or rmb1 = "" Then
drmb = ""
Exit Function
End If If bb = 0 Then
If cc = 0 Then
drmb = drmb & "整"
Exit Function
ElseIf aa <> 0 Then
drmb = drmb & "零" & dcc & "分"
Else
drmb = drmb & dcc & "分"
End If
Else
If cc = 0 Then
drmb = drmb & dbb & "角整"
Exit Function
End If
drmb = drmb & dbb & "角" & dcc & "分"
End If End Function
|