Skip to main content
 Web开发网 » office教程 » excel教程

[程序设计]求助EXCEL高手,特别是精通宏的朋友!

2021年11月25日5190百度已收录

我在网上找到了一个朋友发表的关于将数字大小写的转换过程代码,但不知道怎样才能按照他说的那样另存为加载宏,大家帮我看看。

高人的原代码:

  Private Function hhhh(i As Range)

   If i.Value >= 1 Then

   If Int(i) = i Or Round(i, 2) = Int(i) Then

   hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元整"

   ElseIf Int(i * 10) = i * 10 Or Int(i) * 10 = Round(i, 2) * 10 Then

   hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "角整"

   Else

   hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分"

   End If

   ElseIf i.Value < 1 And i.Value > 0 Then

   If Int(i * 10) = i * 10 Then

   hhhh = Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"

   Else

   hhhh = Application.WorksheetFunction.Text(Left(Right(i, 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "分"

   End If

   ElseIf i = o Then hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元"

   Else

   If Int(i) = i Then

   hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元"

   ElseIf Int(i * 10) = i * 10 Or Round(Abs(i), 2) * 10 = Int(Abs(i)) * 10 Then

   hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"

   Else

   hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "分" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分"

   End If

   End If

   End Function

   具体的操作是,按ALT+F11.打开VBE窗口,"插入"_"模块",将上面的这段代码复制过去

   另存为"加载宏",文件名可以取"金额大小写转换"

   以后要调用就在EXCEL里,"工具","加项宏","浏览",将它选中,双击即装入了.

   它的使用与SUM()等函数一样.

   如

   A B

   1 12345.1=hhhh(a1)结果;壹万贰仟叁佰肆拾伍元壹角整

   2 12345.12 =hhhh(a2)壹万贰仟叁佰肆拾伍元壹角贰分

   3 12345 =hhhh(a3)壹万贰仟叁佰肆拾伍元整

   4 0 =hhhh(a4)零元

   5 -12345 =hhhh(a5)负壹万贰仟叁佰肆拾伍元

   6 -12345.1 =hhhh(a6)负壹万贰仟叁佰肆拾伍元壹角

   7 -12345.12 =hhhh(a7)负壹万贰仟叁佰肆拾伍元壹分贰分

  上面就是高人的东东,但我按照他的指令,却找不到另存为的地方。希望大家能够帮助一下哈,谢谢了哟!

评论列表暂无评论
发表评论
微信