Option Explicit
Sub test()
Dim i&, Z, xA As Range, T$
Set Z = CreateObject("Scripting.Dictionary")
Set xA = [C2:H5]
For i = 1 To xA.Count
T = xA(i): xA(i)(1, 9) = IIf(Z(T) = "", "", xA(i)(1, 5) - Z(T)): Z(T) = xA(i)(1, 5)
Next
End Sub作者: 准提部林 時間: 2024-2-5 15:24
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, [B5:B210000]) Is Nothing Then
Range("V" & Target.Row).Formula = "這裡"
ElseIf Not Intersect(Target, [C5:C210000]) Is Nothing Then
Range("W" & Target.Row).Formula = "這裡"
End If
Application.EnableEvents = True
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, [B5:B210000]) Is Nothing Then
Range("V" & Target.Row).FormulaArray = "=IF(AND(RC[-20]=R[-1]C[-20],RC[-19]=R[-1]C[-19],RC[-18]=R[-1]C[-18],RC[-17]=R[-1]C[-17],RC[-16]=R[-1]C[-16]),RC[-10]-R[-1]C[-10]+RC[-9]-R[-1]C[-9]+RC[-8]-R[-1]C[-8]+RC[-7]-R[-1]C[-7]+RC[-6]-R[-1]C[-6],IF(OR(R4C2:R[-1]C6=RC[-20]),RC[-10]-MOD(MAX((R4C2:R[-1]C6=RC[-20])*(ROW(R1C1:R[-4]C1)*10^5+R4C12:R[-1]C16)),10^5),0)+IF(OR(R4C2:R[-1]C6=RC[-19]),RC[-9]-MOD(MAX((R4C2:R[-1]C6=RC[-19])*(ROW(R1C1:R[-4]C1)*10^5+R4C12:R[-1]C16)),10^5),0)+IF(OR(R4C2:R[-1]C6=RC[-18]),RC[-8]-MOD(MAX((R4C2:R[-1]C6=RC[-18])*(ROW(R1C1:R[-4]C1)*10^5+R4C12:R[-1]C16)),10^5),0)+IF(OR(R4C2:R[-1]C6=RC[-17]),RC[-7]-MOD(MAX((R4C2:R[-1]C6=RC[-17])*(ROW(R1C1:R[-4]C1)*10^5+R4C12:R[-1]C16)),10^5),0)+IF(OR(R4C2:R[-1]C6=RC[-16]),RC[-6]-MOD(MAX((R4C2:R[-1]C6=RC[-16])*(ROW(R1C1:R[-4]C1)*10^5+R4C12:R[-1]C16)),10^5),0))"
ElseIf Not Intersect(Target, [C5:C210000]) Is Nothing Then
Range("W" & Target.Row).FormulaArray = "=IF(AND(RC[-16]=R[-1]C[-16],RC[-15]=R[-1]C[-15],RC[-14]=R[-1]C[-14],RC[-13]=R[-1]C[-13],RC[-12]=R[-1]C[-12]),RC[-6]-R[-1]C[-6]+RC[-5]-R[-1]C[-5]+RC[-4]-R[-1]C[-4]+RC[-3]-R[-1]C[-3]+RC[-2]-R[-1]C[-2],IF(OR(R4C7:R[-1]C11=RC[-16]),RC[-6]-MOD(MAX((R4C7:R[-1]C11=RC[-16])*(ROW(R1C1:R[-4]C1)*10^5+R4C17:R[-1]C21)),10^5),0)+IF(OR(R4C7:R[-1]C11=RC[-15]),RC[-5]-MOD(MAX((R4C7:R[-1]C11=RC[-15])*(ROW(R1C1:R[-4]C1)*10^5+R4C17:R[-1]C21)),10^5),0)+IF(OR(R4C7:R[-1]C11=RC[-14]),RC[-4]-MOD(MAX((R4C7:R[-1]C11=RC[-14])*(ROW(R1C1:R[-4]C1)*10^5+R4C17:R[-1]C21)),10^5),0)+IF(OR(R4C7:R[-1]C11=RC[-13]),RC[-3]-MOD(MAX((R4C7:R[-1]C11=RC[-13])*(ROW(R1C1:R[-4]C1)*10^5+R4C17:R[-1]C21)),10^5),0)+IF(OR(R4C7:R[-1]C11=RC[-12]),RC[-2]-MOD(MAX((R4C7:R[-1]C11=RC[-12])*(ROW(R1C1:R[-4]C1)*10^5+R4C17:R[-1]C21)),10^5),0))"
End If
Application.EnableEvents = True
檔案測不了//
可用另一方式:利用一儲存格(例如:V4)輸入陣列公式, 執行時用V4去COPY
If Not Intersect(Target, [B5:B210000]) Is Nothing Then
Range("V4").Copy Range("V" & Target.Row)作者: 藍天麗池 時間: 2024-2-17 21:09