|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我做的函数,我一直在用
不受直接使用EXCEL中IF函数的嵌套数限制,数值最大可到千亿位
EXCEL单元格只显示公式=SAY(),不显示庞大的IF公式
Function SAY(number)<BR> 'Function say(),progremmed by 长安布衣,2002-2-7<BR> 'Amended 2002-3-29 15:39<BR> 'At Changan<BR> 'email:mrttl@hotmail.com
num_int = number * 100<BR> str_0 = "零壹贰叁肆伍陆柒捌玖"<BR> str_1 = "仟佰拾亿仟佰拾万仟佰拾元角分"<BR> num_lth = Len(Str(num_int)) - 1<BR> str_say0 = ""<BR> For i = 1 To num_lth<BR> str_chr = Mid$(Str$(num_int), i + 1, 1)<BR> num_chr = Val(str_chr)<BR> str_s1 = Mid$(str_0, num_chr + 1, 1)<BR> str_s2 = Mid$(str_1, 14 - (num_lth - i), 1)<BR> str_say1 = str_say0 + str_s1 + str_s2<BR> str_say0 = str_say1<BR> Next<BR> SAY = str_say1<BR> If number < 0 Then<BR> SAY = "(负数)" + SAY<BR> End If<BR> ' remove the "仟" when it after the "零"<BR> zeronum = InStr(1, SAY, "零仟")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零仟")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "佰" when it after the "零"<BR> zeronum = InStr(1, SAY, "零佰")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零佰")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "拾" when it after the "零"<BR> zeronum = InStr(1, SAY, "零拾")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零拾")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "角" when it after the "零"<BR> zeronum = InStr(1, SAY, "零角")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零角")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "分" when it after the "零"<BR> zeronum = InStr(1, SAY, "零分")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零分")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "零亿" with "亿零"<BR> zeronum = InStr(1, SAY, "零亿")<BR> If zeronum > 0 Then<BR> SAY = Left(SAY, zeronum - 1) + "亿零" + Right(SAY, len_say - zeronum - 1)<BR> End If<BR> ' remove the "零万" with "万零"<BR> zeronum = InStr(1, SAY, "零万")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "万零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零万")<BR> len_say = Len(SAY)<BR> Loop<BR> ' remove the "零元" with "元零"<BR> zeronum = InStr(1, SAY, "零元")<BR> len_say = Len(SAY)<BR> If zeronum > 0 Then<BR> SAY = Left(SAY, zeronum - 1) + "元零" + Right(SAY, len_say - zeronum - 1)<BR> End If<BR> <BR> ' remove the "零零" with "零"<BR> zeronum = InStr(1, SAY, "零零")<BR> len_say = Len(SAY)<BR> Do While zeronum > 0<BR> SAY = Left(SAY, zeronum - 1) + "零" + Right(SAY, len_say - zeronum - 1)<BR> zeronum = InStr(1, SAY, "零零")<BR> len_say = Len(SAY)<BR> Loop<BR> <BR> ' remove the "零亿" with "亿"<BR> zeronum = InStr(1, SAY, "零亿")<BR> len_say = Len(SAY)<BR> If zeronum > 0 Then<BR> SAY = Left(SAY, zeronum - 1) + "亿" + Right(SAY, len_say - zeronum - 1)<BR> End If<BR> ' remove the "零元" with "元"<BR> zeronum = InStr(1, SAY, "零元")<BR> len_say = Len(SAY)<BR> If zeronum > 0 Then<BR> SAY = Left(SAY, zeronum - 1) + "元" + Right(SAY, len_say - zeronum - 1)<BR> End If<BR> ' remove the "万" after "亿"<BR> zeronum = InStr(1, SAY, "亿万")<BR> len_say = Len(SAY)<BR> If zeronum > 0 Then<BR> SAY = Left(SAY, zeronum - 1) + "亿" + Right(SAY, len_say - zeronum - 1)<BR> End If<BR> ' remove "零" with "整" at the end of SAY()<BR> zeronum = Right(SAY, 1)<BR> len_say = Len(SAY)<BR> If zeronum = "零" Then<BR> SAY = Left(SAY, len_say - 1) + "整"<BR> End If<BR> If SAY = "整" Then<BR> SAY = "零元整"<BR> End If<BR> End Function
[此贴子已经被作者于2004-3-20 12:48:37编辑过] |
|