|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 wzsy2_mrf 于 2014-7-28 16:40 编辑
先将数据用下面代码进行标准化处理:- Private Function toNumBZH(mystr As String) As String '此函数将输入的中文数字(允许大写、小写、数字、西文空格混编,如有其它字符出现则输出为空串)
- Dim i%, k%, k1%, myPos1%
- Dim str1$, comString$
- comString = "一壹二贰三叁四肆五伍六陆七柒八捌九玖零〇十拾百佰千仟万萬亿億兆0123456789"
- mystr = Replace(mystr, " ", "")
- mystr = Replace(mystr, "貳", "2")
- mystr = Replace(mystr, "陸", "6")
- mystr = Replace(mystr, "两", "2")
- For i = 1 To Len(mystr)
- str1 = Mid(mystr, i, 1)
- myPos1 = InStr(1, comString, str1, vbBinaryCompare)
- If myPos1 = 0 Then Exit Function
- Select Case myPos1
- Case 1 To 18
- mystr = Replace(mystr, str1, Trim(Str(Int((myPos1 + 1) / 2))))
- Case 19, 20
- mystr = Replace(mystr, str1, "0")
- Case 22, 24, 26, 28, 30
- mystr = Replace(mystr, str1, Mid(comString, myPos1 - 1, 1))
- End Select
- Next
- For i = 1 To Len(mystr)
- str1 = Mid(mystr, i, 1)
- myPos1 = InStr(1, comString, str1, vbBinaryCompare)
- If myPos1 >= 21 And myPos1 <= 31 Then k1 = i
- If str1 = "0" Then
- k = InStr(1, comString, Mid(mystr, i + 1, 1), vbBinaryCompare)
- If k >= 21 And k <= 31 And Val(Mid(mystr, k1 + 1, i - k1)) = 0 Then mystr = Left$(mystr, i - 1) & "1" & Right$(mystr, Len(mystr) - i)
- End If
- Next
- toNumBZH = mystr
- End Function
复制代码 |
|