ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

vba¤ñ¹ï¨â¥÷¸ê®Æ¬O§_¤@¼Ë¦C¥X®t²§

vba¤ñ¹ï¨â¥÷¸ê®Æ¬O§_¤@¼Ë¦C¥X®t²§

­Ó¦ì¤j¯«½Ð±Ð¤@¤U,§Ú·Q­n¤ñ¹ï¨â¥÷¸ê®Æ¬O§_¤@¼Ë,¦C¥X®t²§³¡¥÷,vba¦p¦ó°µ Excel¤ñ¹ï¸ê®Æ.rar (10.55 KB)

¦^´_ 1# aassddff736


    ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò
«á¾ÇÂǦ¹©«½m²ß°}¦C»P¦r¨å,¾Ç²ß¤è®×¦p¤U,½Ð«e½ú°Ñ¦Ò

Option Explicit
Sub TEST1()
Dim Arr, Brr, Crr, K, Z, N&, i&, j%, R&, Ta$, Tb$, xR As Range
Set Z = CreateObject("Scripting.Dictionary")
Arr = Range([a¸ê®Æ!F1], [a¸ê®Æ!A65536].End(3)): Brr = Range([b¸ê®Æ!F1], [b¸ê®Æ!A65536].End(3))
ReDim Crr(1 To (UBound(Arr) + UBound(Brr)), 1 To 2)
For i = 2 To UBound(Arr)
   Ta = Trim(Arr(i, 1)): If Ta <> "" Then Z(Ta) = Z(Ta) + 1: Z(Ta & "/Ra") = i: Arr(i, 6) = "": R = R + 1: Crr(R, 1) = Ta: Crr(R, 2) = 1
Next
For i = 2 To UBound(Brr)
   Tb = Trim(Brr(i, 1)): If Z(Tb) = 0 Then R = R + 1: Crr(R, 1) = Tb Else Crr(Z(Tb & "/Ra") - 1, 2) = Crr(Z(Tb & "/Ra") - 1, 2) + 1
   If Tb <> "" Then Z(Tb) = Z(Tb) + 1: Z(Tb & "/Rb") = i: Brr(i, 6) = ""
Next
For Each K In Z.KEYS
   If InStr(K, "/") = 0 And Z(K) = 2 Then N = N + 1: Arr(Z(K & "/Ra"), 6) = N: Brr(Z(K & "/Rb"), 6) = N
Next
Application.Goto [¤ñ¹ïµ²ªG!A1]
ActiveSheet.UsedRange.Clear: [A:B,H:H].NumberFormatLocal = "@"
With [A2].Resize(R, 2): .Value = Crr: .Sort KEY1:=.Item(2), Order1:=2, Header:=1: [A1] = "NUMBER": End With
With [B1].Resize(UBound(Arr), 6): .Value = Arr: .Sort KEY1:=.Item(6), Order1:=1, Header:=1: Arr = .Value: End With
With [H1].Resize(UBound(Brr), 6): .Value = Brr: .Sort KEY1:=.Item(6), Order1:=1, Header:=1: Brr = .Value: End With
[G:G,M:M].ClearContents: Set xR = ActiveSheet.UsedRange.Offset(N + 1, 1)
For i = 2 To N + 1
   For j = 3 To 6: Set xR = IIf(Val(Arr(i, j)) <> Val(Brr(i, j)), Union(xR, Cells(i, j + 1)), xR): Next
Next
Intersect(Union(xR, xR.Offset(, 6)), ActiveSheet.UsedRange).Font.ColorIndex = 3
With Sheets("¯d¤U¬Û¦P")
   .UsedRange.Clear: ActiveSheet.UsedRange.Copy .[A1]: .Range(Intersect(xR, ActiveSheet.UsedRange).Address).EntireRow.Delete
End With
With Sheets("¯d¤U®t²§")
   .UsedRange.Clear: Intersect(Union([A1], xR), ActiveSheet.UsedRange).EntireRow.Copy .[A1]
End With
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 2# Andy2483
ÁÂÁ±zªº±Ð¾É
¦pªG§Ú¤ñ¹ï¸ê®ÆÄæ¼Æ¤£©T©w
¤ñ¹ïµ²ªGAÄæ·Q§e²{©Ò¦³¸ê®Æ,®t²§¼Ð¬õ¦â·s¼W¼ÐÂŦâ
¦p¦ó°µ?



Excel¤ñ¹ï¸ê®Æ.rar (20.86 KB)

TOP

¦^´_ 3# aassddff736

¥H¤U¬OÄæ¼Æ¤£©T©w,¥H­ì±Æ§Ç¤è¦¡ªº¤è®×,½Ð«e½ú°Ñ¦Ò
Option Explicit
Sub TEST1()
Dim Arr, Brr, Crr, C%, K, Z, N&, i&, j%, R&, Ta$, Tb$, xR As Range
Set Z = CreateObject("Scripting.Dictionary")
Set Arr = Sheets(1).[A1].CurrentRegion: Arr = Union(Arr, Arr.Offset(, 1)): Set Brr = Sheets(2).[A1].CurrentRegion: Brr = Union(Brr, Brr.Offset(, 1))
C = UBound(Arr, 2): If C <> UBound(Brr, 2) Then Exit Sub
ReDim Crr(1 To (UBound(Arr) + UBound(Brr)), 1 To 2)
For i = 1 To UBound(Arr)
   Ta = Trim(Arr(i, 1)): If Ta <> "" Then Z(Ta) = Z(Ta) + 1: Z(Ta & "/Ra") = i: R = R + 1: Crr(R, 1) = Ta: Crr(R, 2) = 1
Next
For i = 1 To UBound(Brr)
   Tb = Trim(Brr(i, 1)): If Z(Tb) = 0 Then R = R + 1: Crr(R, 1) = Tb Else Crr(Z(Tb & "/Ra"), 2) = Crr(Z(Tb & "/Ra"), 2) + 1
   If Tb <> "" Then Z(Tb) = Z(Tb) + 1: Z(Tb & "/Rb") = i
Next
For Each K In Z.KEYS
   If InStr(K, "/") = 0 And Z(K) = 2 Then N = N + 1: Arr(Z(K & "/Ra"), C) = N: Brr(Z(K & "/Rb"), C) = N
Next
Application.Goto [¤ñ¹ïµ²ªG!A1]
ActiveSheet.UsedRange.Clear: [A1] = "NUMBER"
With [A2].Resize(R, 2): .Value = Crr: .Sort KEY1:=.Item(2), Order1:=2, Header:=1: .Columns(2).ClearContents: End With
With [B2].Resize(UBound(Arr), C): .Value = Arr: .Sort KEY1:=.Item(C), Order1:=1, Header:=1: Arr = .Value: .Columns(C).ClearContents: End With
With Cells(2, C + 2).Resize(UBound(Brr), C): .Value = Brr: .Sort KEY1:=.Item(C), Order1:=1, Header:=1: Brr = .Value: .Columns(C).ClearContents: End With
[B1] = "New": [B1].Resize(, C - 1).Merge: [B1].Item(, C + 1) = "Old": [B1].Item(, C + 1).Resize(, C - 1).Merge
Set xR = ActiveSheet.UsedRange.Offset(N + 1, 1)
For i = 1 To N
   For j = 3 To C: Set xR = IIf(Val(Arr(i, j)) <> Val(Brr(i, j)), Union(xR, Cells(i + 1, j + 1), Cells(i + 1, 2)), xR): Next
Next
Intersect(Union(xR, xR.Offset(, C)), ActiveSheet.UsedRange).Font.ColorIndex = 3
With Sheets("¯d¤U¬Û¦P")
   .UsedRange.Clear: ActiveSheet.UsedRange.Copy .[A1]:   .Range(Intersect(xR.EntireRow, ActiveSheet.UsedRange).Address).EntireRow.Delete
End With
With Sheets("¯d¤U®t²§")
   .UsedRange.Clear: Intersect(Union([A1], xR.EntireRow), ActiveSheet.UsedRange).EntireRow.Copy .[A1]
End With
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 4# Andy2483


  ·PÁ¤j¯««ü±Ð
³o­Ó¦n¹³¬O¦P¦C¤ñ¹ï§Ú·Q­nªº¬O¥u­n¸ê®Æ¬Û¦P¬O¬°¤@¼Ë¤£ºÞ¶¶§Ç
¤ñ¹ïµ²ªGA,B,JÄæ¦ì¸m­n¤@¼Ë

TOP

¦^´_ 4# Andy2483


    ¡¹®y¼Ð¤ñ¹ïÃC¦â½Õ¾ã.zip (58.17 KB)
¯àÀ°§Ú¬Ý¬Ý³o­ÓÀÉ®×
§Ú·Q­n¼W¥[¤@­¶¥u¨q®t²§³¡¤À ¤ñ¹ïµ²ªGnew,old ¶¡¯d¤@¦æªÅ¥Õ¤ñ¸û¨S³o»ò¶Ã

TOP

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2024-2-16 14:52 ½s¿è

¦^´_ 5# aassddff736

¤ñ¹ïµ²ªGA,B,JÄæ¦ì¸m¤@¼Ëªº¤è®×,½Ð«e½ú°Ñ¦Ò

Option Explicit
Sub TEST2()
Dim Arr, Brr, Crr, C%, Z, N&, i&, j%, R&, Ta$, Tb$, xR As Range, xB As Range, xS As Worksheet
Set Z = CreateObject("Scripting.Dictionary"): Set xS = Sheets("¤ñ¹ïµ²ªG")
Set Arr = Sheets(1).[A1].CurrentRegion: Arr = Union(Arr, Arr.Offset(, 1))
Set Brr = Sheets(2).[A1].CurrentRegion: Brr = Union(Brr, Brr.Offset(, 1))
C = UBound(Arr, 2): If C <> UBound(Brr, 2) Then MsgBox "Äæ¼Æ¤£¦P": Exit Sub
ReDim Crr(1 To (UBound(Arr) + UBound(Brr)), 1 To C * 2 + 1)
For i = 1 To UBound(Arr)
   Ta = Trim(Arr(i, 1)): R = R + 1: Z(Ta) = R: Crr(R, 1) = Ta
   For j = 1 To C: Crr(R, j + 1) = Arr(i, j): Next
Next
For i = 1 To UBound(Brr)
   Tb = Trim(Brr(i, 1)): N = Z(Tb): If N = 0 Then R = R + 1: Crr(R, 1) = Tb: N = R: Z(Tb) = R
   For j = 1 To C: Crr(N, j + 1 + C) = Brr(i, j): Next
Next
Application.Goto xS.[A1]
xS.UsedRange.Clear: [A1] = "NUMBER"
With [A2].Resize(R, C * 2 + 1): .Value = Crr: .Sort KEY1:=.Item(2), Order1:=1, Header:=2: Crr = .Value: End With
[B1] = "New": [B1].Resize(, C - 1).Merge: [B1].Item(, C + 1) = "Old": [B1].Item(, C + 1).Resize(, C - 1).Merge
Set xR = xS.UsedRange: Set xR = xR(xR.Count + 1): Set xB = xR
For i = 2 To R + 1
   For j = 3 To C
      Set xR = IIf(Crr(i - 1, j) <> Crr(i - 1, j + C), Union(xR, Cells(i, j), Cells(i, 1)), xR)
      If Crr(i - 1, j) = "" Or Crr(i - 1, j + C) = "" Then Set xB = Union(xB, Cells(i, j))
   Next
Next
Union(xR, xR.Offset(, C)).Font.ColorIndex = 3
xB.EntireRow.Font.ColorIndex = 5
With Sheets("¯d¤U¬Û¦P")
   .UsedRange.Clear: xS.UsedRange.Copy .[A1]
   .Range(Intersect(xR.EntireRow, xS.UsedRange).Address).EntireRow.Delete
End With
With Sheets("¯d¤U®t²§")
   .UsedRange.Clear: Intersect(Union([A1], xR.EntireRow), xS.UsedRange).EntireRow.Copy .[A1]
End With
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 6# aassddff736

¥u¨q®t²§³¡¤À ¤ñ¹ïµ²ªGnew,old ¶¡¯d¤@¦æªÅ¥Õ ¤è®×¦p¤U,½Ð«e½ú°Ñ¦Ò
Option Explicit
Sub TEST2()
Dim Arr, Brr, Crr, C%, Z, N&, i&, j%, R&, Ta$, Tb$, xR As Range, xB As Range, xS As Worksheet
Set Z = CreateObject("Scripting.Dictionary"): Set xS = Sheets("Result")
Set Arr = Sheets(2).[A1].CurrentRegion: Arr = Union(Arr, Arr.Offset(, 1))
Set Brr = Sheets(3).[A1].CurrentRegion: Brr = Union(Brr, Brr.Offset(, 1))
C = UBound(Arr, 2): If C <> UBound(Brr, 2) Then MsgBox "Äæ¼Æ¤£¦P": Exit Sub
ReDim Crr(1 To (UBound(Arr) + UBound(Brr)), 1 To C * 2 + 1)
For i = 1 To UBound(Arr)
   Ta = Trim(Arr(i, 1)): R = R + 1: Z(Ta) = R: Crr(R, 1) = Ta
   For j = 1 To C: Crr(R, j + 1) = Arr(i, j): Next
Next
For i = 1 To UBound(Brr)
   Tb = Trim(Brr(i, 1)): N = Z(Tb): If N = 0 Then R = R + 1: Crr(R, 1) = Tb: N = R: Z(Tb) = R
   For j = 1 To C: Crr(N, j + 1 + C) = Brr(i, j): Next
Next
Application.Goto xS.[A1]
xS.UsedRange.Clear: [A1] = "NUMBER"
With [A2].Resize(R, C * 2 + 1): .Value = Crr: .Sort KEY1:=.Item(2), Order1:=1, Header:=1: Crr = .Value: End With
[B1] = "New": [B1].Resize(, C - 1).Merge: [B1].Item(, C + 1) = "Old": [B1].Item(, C + 1).Resize(, C - 1).Merge
Set xR = xS.UsedRange: Set xR = xR(xR.Count + 1): Set xB = xR
For i = 2 To R + 1
   For j = 3 To C
      Set xR = IIf(Crr(i - 1, j) <> Crr(i - 1, j + C), Union(xR, Cells(i, j), Cells(i, 1)), xR)
      If Crr(i - 1, j) = "" Or Crr(i - 1, j + C) = "" Then Set xB = Union(xB, Cells(i, j))
   Next
Next
Union(xR, xR.Offset(, C)).Font.ColorIndex = 3
xB.EntireRow.Font.ColorIndex = 5
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 7# Andy2483


¥i¥H¤F¤] ÁÂÁ¤j¯«
¯à¨Ì·ÓAÄæ±Æ§Ç¶Ü?

TOP

¦^´_ 9# aassddff736


    .Sort KEY1:=.Item(2) §ï¬° .Sort KEY1:=.Item(1)
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

        ÀR«ä¦Û¦b : ¤H¨ÆªºÁ}Ãø»PµZ¿i¡A´N¬O¤@ºØ¦ÒÅç¡C
ªð¦^¦Cªí ¤W¤@¥DÃD