2,462
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Function MyNumberString(objRange)
Dim strNumber As String
strNumber = Application.WorksheetFunction.Text(objRange, "[dbnum2]")
Dim reg As Object
Set reg = CreateObject("vbscript.regexp")
reg.Global = True
reg.MultiLine = False
reg.ignorecase = True
reg.Pattern = "^(.*)\.(.)?(.)?$"
If reg.test(strNumber) Then
Dim objMatch As Object
Set objMatch = reg.Execute(strNumber)(0)
If objMatch.submatches(1) = "" Then
strNumber = objMatch.submatches(0) & "元整"
ElseIf objMatch.submatches(2) = "" Then
strNumber = objMatch.submatches(0) & "元" & objMatch.submatches(1) & "角零分"
Else
strNumber = objMatch.submatches(0) & "元" & objMatch.submatches(1) & "角" & objMatch.submatches(2) & "分"
End If
Else
strNumber = strNumber & "元整"
End If
Dim lngNumber As Long
lngNumber = CLng(objRange.Value)
If lngNumber > 10000 And (lngNumber / 10000) Mod 10 = 0 Then
strNumber = Replace(strNumber, "万", "万零")
End If
MyNumberString = strNumber
End Function