為什麼照抄的代碼運行結果不一樣
發布時間: 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
熱點內容