为什么照抄的代码运行结果不一样
发布时间: 2024-10-23 04:48:16
㈠ EXCEL 多种选项条件对应多个结果 怎么用VBA解决
首先打开excel,按alt+f11,打开vba编辑器,然后插入一个模块,模块内容如下,你照抄过去
SubA()
DimA#,B#,C#,D#,E#,F#,G#,H#,I#,M#,X#
DimHangAsLong
ForHang=2ToRange("a1").End(xlDown).RowStep3
A=Cells(Hang,1):B=Cells(Hang,2):C=Cells(Hang+1,2):Cells(Hang+2,2)=B+C
D=Cells(Hang+2,2)
E=Cells(Hang,3):F=Cells(Hang+1,3):G=Cells(Hang+2,3)
IfA<=BThen
Cells(Hang,4)=A*E:Cells(Hang+1,4)=0:Cells(Hang+2,4)=0
EndIf
IfA>BAndA<=DThen
Cells(Hang,4)=B*E:Cells(Hang+1,4)=(A-B)*F:Cells(Hang+2,4)=0
EndIf
IfA>DThen
Cells(Hang,4)=B*E:Cells(Hang+1,4)=C*F:Cells(Hang+2,4)=(A-D)*G
EndIf
Cells(Hang,5)=Cells(Hang,4)+Cells(Hang+1,4)+Cells(Hang+2,4)
NextHang
EndSub
热点内容