Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2798|回复: 3

[已解决]把大写变成小写数字

[复制链接]
发表于 2015-1-20 18:49 | 显示全部楼层 |阅读模式
本帖最后由 zss7758258 于 2015-1-22 13:58 编辑

根据A列得出B列的结果,函数也好VBA也好,出结果就行了,谢谢老师们!

把大写变成小写.png
最佳答案
2015-1-22 11:01
  1. Function TxtToDigits(Xstr) As Long      '汉字转数字
  2.     If InStr(Xstr, "万") > 0 Then
  3.         x = Split(Xstr, "万")
  4.         TxtToDigits = Four_Digits(x(0)) * 10000# + Four_Digits(x(1))
  5.     Else
  6.         TxtToDigits = Four_Digits(Xstr)
  7.     End If
  8. End Function

  9. Function Four_Digits(Xstr) As Integer      '四位数
  10.     arr = Array("一", "二", "三", "四", "五", "六", "七", "八", "九")
  11.     Set d = CreateObject("scripting.dictionary")
  12.     For i = 0 To UBound(arr)
  13.         d(arr(i)) = i + 1
  14.     Next
  15.     If Xstr Like "十*" Then Xstr = Replace(Xstr, "十", "一十")
  16.     Xstr = Replace(Xstr, "零", "")
  17.     If InStr(Xstr, "千") > 0 Then
  18.         x = Left(Xstr, 1): Four_Digits = d(x) * 1000: Xstr = Replace(Xstr, x & "千", "")
  19.     End If
  20.     If InStr(Xstr, "百") > 0 Then
  21.         x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 100: Xstr = Replace(Xstr, x & "百", "")
  22.     End If
  23.     If InStr(Xstr, "十") > 0 Then
  24.         x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 10: Xstr = Replace(Xstr, x & "十", "")
  25.     End If
  26.     If Len(Xstr) > 0 Then Four_Digits = Four_Digits + d(Left(Xstr, 1))
  27. End Function
复制代码
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-1-21 11:20 | 显示全部楼层
楼主再提问题需做好附件并模拟好结果上传上来,方便大家帮你。
  1. Sub test()
  2.     Dim arr, i%, j%
  3.     arr = Range("a1:a" & [a65536].End(3).Row)
  4.     For i = 1 To UBound(arr)
  5.         If arr(i, 1) Like "十*" Then arr(i, 1) = Replace(arr(i, 1), "十", "一十")
  6.         For j = 1 To 100
  7.             If Application.Text(j, "[dbnum1]") = arr(i, 1) Then arr(i, 1) = j: Exit For
  8.         Next
  9.     Next
  10.     [b1].Resize(i - 1) = arr
  11. End Sub
复制代码
中文数字转阿拉伯数字.rar (14.83 KB, 下载次数: 10)

评分

参与人数 1 +3 收起 理由
zss7758258 + 3 很给力!谢谢老师的指点,受教了!

查看全部评分

回复

使用道具 举报

发表于 2015-1-22 11:01 | 显示全部楼层    本楼为最佳答案   
  1. Function TxtToDigits(Xstr) As Long      '汉字转数字
  2.     If InStr(Xstr, "万") > 0 Then
  3.         x = Split(Xstr, "万")
  4.         TxtToDigits = Four_Digits(x(0)) * 10000# + Four_Digits(x(1))
  5.     Else
  6.         TxtToDigits = Four_Digits(Xstr)
  7.     End If
  8. End Function

  9. Function Four_Digits(Xstr) As Integer      '四位数
  10.     arr = Array("一", "二", "三", "四", "五", "六", "七", "八", "九")
  11.     Set d = CreateObject("scripting.dictionary")
  12.     For i = 0 To UBound(arr)
  13.         d(arr(i)) = i + 1
  14.     Next
  15.     If Xstr Like "十*" Then Xstr = Replace(Xstr, "十", "一十")
  16.     Xstr = Replace(Xstr, "零", "")
  17.     If InStr(Xstr, "千") > 0 Then
  18.         x = Left(Xstr, 1): Four_Digits = d(x) * 1000: Xstr = Replace(Xstr, x & "千", "")
  19.     End If
  20.     If InStr(Xstr, "百") > 0 Then
  21.         x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 100: Xstr = Replace(Xstr, x & "百", "")
  22.     End If
  23.     If InStr(Xstr, "十") > 0 Then
  24.         x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 10: Xstr = Replace(Xstr, x & "十", "")
  25.     End If
  26.     If Len(Xstr) > 0 Then Four_Digits = Four_Digits + d(Left(Xstr, 1))
  27. End Function
复制代码
回复

使用道具 举报

发表于 2015-1-22 11:02 | 显示全部楼层
可到99999999。

中文数字转阿拉伯数字.rar

15.45 KB, 下载次数: 6

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-20 21:01 , Processed in 0.393069 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表