Dim OUT1
Private Sub Worksheet_Change(ByVal Target As Range)
If OUT1 = True Then Exit Sub
If Target.Height > 10000 Then Exit Sub
If Target.Width > 10000 Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Target.Row > 1 Then Exit Sub
If Target.Column = 11 Then
ElseIf Target.Column = 14 Then
ElseIf Target.Column = 17 Then
ElseIf Target.Column = 20 Then
Else
Exit Sub
End If
OUT1 = True
Target.Offset(1, 0).Resize(100000, 2).ClearContents
OUT1 = False
r = Cells(Rows.Count, 1).End(3).Row
For i = 2 To r
If UCase(Target.Value) = UCase(Cells(i, 3).Value) Then
OUT1 = True
For j = i To Cells(i, 3).MergeArea.Count + i - 1
w = w + 1
Target.Offset(w, 0).Resize(1, 2).Value = Cells(j, 4).Resize(1, 2).Value
sumx = sumx + Cells(j, 5)
Next
End If
Next
If w <> 0 Then Target.Offset(w + 1, 0).Resize(1, 2) = Array("Total", sumx)
OUT1 = False
End Sub§@ªÌ: 198188 ®É¶¡: 2023-12-21 09:21
Y·Qn¥´§¹¦A¤â°Ê°õ¦æ¥Î¦p¤U¥N½X
Sub test()
r = Cells(Rows.Count, 1).End(3).Row
Range("k2:u1000").ClearContents
For Each Z In Range("K1,N1,Q1,T1")
t5 = 0: t4 = 0
If Z.Value <> "" Then
For i = 2 To r
If UCase(Z.Value) = UCase(Cells(i, 3).Value) Then
For j = i To Cells(i, 3).MergeArea.Count + i - 1
t4 = t4 & "¡¶" & Cells(j, 4)
t5 = t5 & "¡¶" & Cells(j, 5)
tsum = tsum + Cells(j, 5)
Next
End If
Next
If UBound(a4) > 0 Then
Z.Offset(1, 0).Resize(UBound(a4) + 1, 1) = Application.Transpose(a4)
Z.Offset(1, 1).Resize(UBound(a4) + 1, 1) = Application.Transpose(a5)
End If
End If
Next
¦^´_ 20#198188
ÁÂÁ«e½ú¦A¦^´_·s½d¨Ò,¥H¤U¬O¾Ç²ßªº¤è®×,½Ð«e½ú°Ñ¦Ò
Option Explicit
Sub TEST()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Brr, Crr, Ar, Arr, V, Z, A, i&, R&, C%, j%, T$, K$, Qs$, Qd$, No$, Mk$, Q$
For i = Worksheets.Count To 3 Step -1: Worksheets(i).Delete: Next
Set Z = CreateObject("Scripting.Dictionary")
Brr = Union(Sheets(1).UsedRange, Sheets(1).UsedRange.Offset(1))
Crr = Range(Sheets(2).[A1], Sheets(2).UsedRange): K = [B1]
For i = 1 To UBound(Brr) - 1
If InStr(Brr(i, 1), Left(K, 4)) = 0 Then GoTo i01
A = Split(Replace(Brr(i, 1), " ", " "), " "): Q = Left(A(0), 8): Qd = A(1)
If UBound(A) > 1 Then Qs = A(UBound(A)) Else Qs = ""
A = Z(Q): R = Z(Q & "/r"): C = 1
If Not IsArray(A) Then A = Crr: A(3, 2) = Q: A(3, 6) = Qs: A(3, 9) = Qd: A(4, 13) = Date: R = 5
R = R + 1: V = A(R, 2)
If InStr(Brr(i, 2), V) = 0 Or R = 10 Then GoTo i01
For j = 2 To UBound(Brr, 2)
C = C + 2: T = Trim(Brr(i, j)): If T = "" Then GoTo j01
If InStr(T, V) Then
A(R, C) = Mid(T, 4, 6): A(R, C + 1) = Replace(Mid(T, 11), ")", "")
Else
Ar = Split(T, Chr(10))
For Each Arr In Ar
If Not Split(Arr & " ", " ")(1) Like "[A-z][A-z]" Then GoTo j01
No = No & Chr(10) & Split(Arr, " ")(0)
Mk = Mk & Chr(10) & Mid(Arr, InStr(Arr, Split(Arr, " ")(1)))
Next
A(R, C) = Mid(No, 2): A(R, C + 1) = Mid(Mk, 2): No = "": Mk = ""
End If
j01: Next
Z(Q) = A: Z(Q & "/r") = R
i01: Brr(i + 1, 1) = IIf(Brr(i + 1, 1) = "", Brr(i, 1), Brr(i + 1, 1))
Next
If Z.Count = 0 Then Exit Sub
For Each A In Z.KEYS
If Not IsArray(Z(A)) Then GoTo A01
With Sheets(2).Copy(after:=Worksheets(Sheets.Count))
ActiveSheet.Name = "Result " & A
[A1].Resize(UBound(Z(A)), UBound(Z(A), 2)) = Z(A)
End With
A01: Next
Application.Goto Sheets(1).[A1]
End Sub§@ªÌ: 198188 ®É¶¡: 2024-1-2 13:53
Option Explicit
Sub Map()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Brr, Crr, Ar, Arr, V, Z, A, i&, R&, C%, j%, T$, K$, Qs$, Qd$, No$, Mk$, Q$, S%
For i = Worksheets.Count To 4 Step -1: Worksheets(i).Delete: Next
Set Z = CreateObject("Scripting.Dictionary")
Brr = Sheets(3).UsedRange
For i = 1 To UBound(Brr): Z(Trim(Brr(i, 1))) = Trim(Brr(i, 2)): Next: S = Z.Count
Brr = Union(Sheets(1).UsedRange, Sheets(1).UsedRange.Offset(1))
Crr = Range(Sheets(2).[A1], Sheets(2).UsedRange): K = [B1]
For i = 1 To UBound(Brr) - 1
If InStr(Brr(i, 1), Left(K, 4)) = 0 Then GoTo i01
A = Split(Replace(Brr(i, 1), " ", " "), " "): Q = Mid(A(0), 5, 4): Qd = A(1)
If UBound(A) > 1 Then Qs = A(UBound(A)) Else Qs = ""
A = Z(Q): R = Z(Q & "/r"): C = 1
If Not IsArray(A) Then A = Crr: A(3, 2) = Q: A(3, 6) = Qs: A(3, 9) = Qd: A(4, 13) = Date: R = 5
R = R + 1: V = A(R, 2)
If InStr(Brr(i, 2), V) = 0 Or R = 10 Then GoTo i01
For j = 2 To UBound(Brr, 2)
C = C + 2: T = Trim(Brr(i, j)): If T = "" Then GoTo j01
If InStr(T, V) Then
A(R, C) = Mid(T, 4, 6): A(R, C + 1) = Replace(Mid(T, 11), ")", "")
Else
Ar = Split(T, Chr(10))
For Each Arr In Ar
If Not Split(Arr & " ", " ")(1) Like "[A-z][A-z]" Then GoTo j01
No = No & Chr(10) & Split(Arr, " ")(0): Mk = Mk & Chr(10) & Mid(Arr, InStr(Arr, Split(Arr, " ")(1)))
Next
A(R, C) = Mid(No, 2): A(R, C + 1) = Mid(Mk, 2): No = "": Mk = ""
End If
j01: Next
Z(Q) = A: Z(Q & "/r") = R
i01: Brr(i + 1, 1) = IIf(Brr(i + 1, 1) = "", Brr(i, 1), Brr(i + 1, 1))
Next
If Z.Count = 0 Then Exit Sub
For Each A In Z.KEYS
If Not IsArray(Z(A)) Then GoTo A01 Else Sheets(2).Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = A '"Result " & A
[A1].Resize(UBound(Z(A)), UBound(Z(A), 2)) = Z(A)
For i = 0 To S - 1: ActiveSheet.UsedRange.Replace Z.KEYS()(i), Z.ITEMS()(i), Lookat:=xlPart: Next
A01: Next
Application.Goto Sheets(1).[A1]
End Sub§@ªÌ: 198188 ®É¶¡: 2024-1-3 14:33