我在excel中建立了一个公式,但太长了,想把它自定义为一个自定义函数,请教大家有没有好的解决办法啊?
我在excel中建立了一个公式,但太长了,想把它自定义为一个自定义函数,请教大家有没有好的解决办法啊?具体是:=IF(RIGHT(TRIM(IF(ISERROR(IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""))=FALSE,IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""),"")&IF(ISERROR(IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""))=FALSE,IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""),"")&IF(ISERROR(IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""))=FALSE,IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""),"")),2)="","外省",IF(RIGHT(TRIM(IF(ISERROR(IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""))=FALSE,IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""),"")&IF(ISERROR(IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""))=FALSE,IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""),"")&IF(ISERROR(IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""))=FALSE,IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""),"")),2)="三水","三水",IF(RIGHT(TRIM(IF(ISERROR(IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""))=FALSE,IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""),"")&IF(ISERROR(IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""))=FALSE,IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""),"")&IF(ISERROR(IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""))=FALSE,IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""),"")),2)="佛山","佛山",IF(RIGHT(TRIM(IF(ISERROR(IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""))=FALSE,IF(MID($D9,FIND("广东",$D9),2)="广东","广东",""),"")&IF(ISERROR(IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""))=FALSE,IF(MID($D9,FIND("佛山",$D9),2)="佛山","佛山",""),"")&IF(ISERROR(IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""))=FALSE,IF(MID($D9,FIND("三水",$D9),2)="三水","三水",""),"")),2)="广东","广东","")))) 可以用VBA写到后台来实现。
如果不明白的话,回复后我写个例子给你 帮顶 帮顶 有个例子看看能不能给你点提示
- - - - - - - - - - - -- - - - - -- 人民币大小写转换- - - -- - - - - -- - - -
1、启动Excel。按Alt+F11键,打开“visual basic编辑器”。 2、在“visual basic编辑器”中,单击“插入”菜单栏中的“模块”命令,插入一个模块。双击左侧“工程”窗口中的“模块1”选项,在窗口右边展开“模块1(代码)”编辑窗口,然后输入公式。(公式我就不发了,网上随便一搜就有很多) 3、输 入完成后,关闭“visual basic编辑器”返回工作表。 4、现在,我们可测试一下这个函数。首先,在a1单元格中输入一个小写数字的金额,例如123456.78,然后,在a2单元 格中输入公式:=N2RMB(a1),确认后即可将a1所表示的小写数字金额转换为大写的数字金额,并在a2单元格中显示出来。
2、N2RMB是模块中通用名称,在模块通用模式下输入以下公式
Function N2RMB(M)
y = Int(Round(100 * Abs(M)) / 100)
j = Round(100 * Abs(M) + 0.00001) - y * 100
f = (j / 10 - Int(j / 10)) * 10
A = IIf(y < 1, "", Application.Text(y, "[DBNum2]") & "元")
b = IIf(j > 9.5, Application.Text(Int(j / 10), "[DBNum2]") & "角", IIf(y < 1, "", IIf(f > 1, "零", "")))
c = IIf(f < 1, "整", Application.Text(Round(f, 0), "[DBNum2]") & "分")
N2RMB = IIf(Abs(M) < 0.005, "", IIf(M < 0, "负" & A & b & c, A & b & c))
End Function
3、以后用的时候就可以公式引用=N2RMB(M)
4、每次新打开一个表,都要新建一次,方可使用 自己写一个公式解析器。
补充:VB , VBA