請測試看看,謝謝
Sub test()
Dim Arr, xD, Brr(), T$, T1$, i&, n%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Sheet1.[A1].CurrentRegion
For i = 2 To UBound(Arr)
T = Arr(i, 3): T1 = Arr(i, 5)
If UCase(T1) = "S" Then
xD(T) = Array(Arr(i, 4), Arr(i, 7))
End If
Next
Arr = Sheet2.[A1].CurrentRegion
ReDim Brr(1 To UBound(Arr), 1 To 7)
For i = 2 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
n = n + 1: Brr(n, 3) = xD(T)(1)
Brr(n, 1) = T: Brr(n, 2) = Arr(i, 2)
If UCase(xD(T)(0)) = "DR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n, 7) = Arr(i, 10)
Else
Brr(n, 7) = Arr(i, 11)
End If
ElseIf UCase(xD(T)(0)) = "CR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n, 7) = -Arr(i, 10)
Else
Brr(n, 7) = -Arr(i, 11)
End If
End If
End If
99: Next
If n > 0 Then
Sheet3.[A8].Resize(n, 7) = Brr
End If
End Sub作者: shuo1125 時間: 2022-5-24 17:51
Sub test()
Dim Arr, xD, Brr(), T$, T1$, i&, n%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Sheet1.[A1].CurrentRegion
For i = 2 To UBound(Arr)
T = Arr(i, 3): T1 = Arr(i, 5)
If UCase(T1) = "S" Then
xD(T) = Array(Arr(i, 4), Arr(i, 7), Arr(i, 2), Arr(i, 10))
End If
Next
Arr = Sheet2.[A1].CurrentRegion
ReDim Brr(1 To UBound(Arr), 1 To 7)
For i = 2 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
n = n + 1: Brr(n, 3) = xD(T)(1)
Brr(n, 1) = xD(T)(2): Brr(n, 2) = xD(T)(3)
If UCase(xD(T)(0)) = "DR" Then
....
....
....作者: shuo1125 時間: 2022-5-25 11:46
請再測試看看,謝謝
Sub test()
Dim Arr, xD, Brr(), T$, T1$, i&, n%, n1%
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
Arr = Sheet1.[A1].CurrentRegion
For i = 2 To UBound(Arr)
T = Arr(i, 3): T1 = Arr(i, 5)
If UCase(T1) = "S" Then
xD(T) = Array(Arr(i, 2), Arr(i, 4), Arr(i, 7), Arr(i, 10))
End If
Next
Arr = Sheet2.[A1].CurrentRegion
ReDim Brr(1 To UBound(Arr), 1 To 7)
For i = 2 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
T1 = xD(T)(0)
If xD1.Exists(T1) Then
n1 = xD1(T1)
If UCase(xD(T)(1)) = "DR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n1, 7) = Brr(n1, 7) + Arr(i, 10)
Else
Brr(n1, 7) = Brr(n1, 7) + Arr(i, 11)
End If
ElseIf UCase(xD(T)(1)) = "CR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n1, 7) = Brr(n1, 7) - Arr(i, 10)
Else
Brr(n1, 7) = Brr(n1, 7) - Arr(i, 11)
End If
End If
Else
n = n + 1: xD1(T1) = n: Brr(n, 3) = xD(T)(2)
Brr(n, 1) = xD(T)(0): Brr(n, 2) = xD(T)(3)
If UCase(xD(T)(1)) = "DR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n, 7) = Arr(i, 10)
Else
Brr(n, 7) = Arr(i, 11)
End If
ElseIf UCase(xD(T)(1)) = "CR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(n, 7) = -Arr(i, 10)
Else
Brr(n, 7) = -Arr(i, 11)
End If
End If
End If
End If
99: Next
If n > 0 Then
With Sheet3
.[a7].CurrentRegion.Offset(5, 0) = ""
.[A8].Resize(n, 7) = Brr
.[G4] = Now
End With
Set xD = Nothing: Erase Arr, Brr
End If
End Sub作者: shuo1125 時間: 2022-5-31 12:41
For i = 2 To UBound(Arr)
T = Arr(i, 1)
If xD.Exists(T) Then
T1 = xD(T)(0)
If xD1.Exists(T1) Then
n1 = xD1(T1): m = n1
Else
n = n + 1: xD1(T1) = n: Brr(n, 3) = xD(T)(2)
Brr(n, 1) = xD(T)(0): Brr(n, 2) = xD(T)(3): m = n
End If
If UCase(xD(T)(1)) = "DR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(m, 7) = Brr(m, 7) + Arr(i, 10)
Else
Brr(m, 7) = Brr(m, 7) + Arr(i, 11)
End If
ElseIf UCase(xD(T)(1)) = "CR" Then
If Arr(i, 10) > Arr(i, 11) Then
Brr(m, 7) = Brr(m, 7) - Arr(i, 10)
Else
Brr(m, 7) = Brr(m, 7) - Arr(i, 11)
End If
End If
'If UCase(xD(T)(1)) = "DR" Then
' If Arr(i, 10) > Arr(i, 11) Then
' Brr(M, 7) = Brr(M, 7) + Arr(i, 10)
' Else
' Brr(M, 7) = Brr(M, 7) + Arr(i, 11)
' End If
' ElseIf UCase(xD(T)(1)) = "CR" Then
' If Arr(i, 10) > Arr(i, 11) Then
' Brr(M, 7) = Brr(M, 7) - Arr(i, 10)
' Else
' Brr(M, 7) = Brr(M, 7) - Arr(i, 11)
' End If
' End If
>>>>>
If UCase(xD(T)(1)) = "DR" Then S = 1 Else S = -1
If Arr(i, 10) > Arr(i, 11) Then C = 10 Else C = 11
Brr(M, 7) = Brr(M, 7) + Arr(i, C) * S作者: shuo1125 時間: 2022-6-4 20:33