返回列表 上一主題 發帖

[發問] 請問怎樣尋找相同的資料

回復 1# john2006168
使用Dictionary 物件   試試看
  1. Sub Ex()
  2.     Dim D As Object, E, S As String, S1 As String
  3.     Set D = CreateObject("SCRIPTING.DICTIONARY")
  4.     With Sheets("Sheet2")
  5.         For Each E In .Range("E2", .[E2].End(xlDown))
  6.             If D.EXISTS(E.Value) = False Then
  7.                 D(E.Value) = Array(E.Offset(, -3), E.Offset(, -4))
  8.             Else
  9.                 S = "," & D(E.Value)(0) & ","
  10.                 If InStr(S, "," & E.Offset(, -3) & ",") = 0 Then
  11.                     S = D(E.Value)(0) & "," & E.Offset(, -3)
  12.                 Else
  13.                     S = D(E.Value)(0)
  14.                 End If
  15.                 S1 = "," & D(E.Value)(1) & ","
  16.                 If InStr(S1, "," & E.Offset(, -4)) & "," = 0 Then
  17.                     S1 = D(E.Value)(1) & "," & E.Offset(, -4)
  18.                 Else
  19.                     S1 = D(E.Value)(1)
  20.                 End If
  21.                 D(E.Value) = Array(S, S1)
  22.             End If
  23.         Next
  24.     End With
  25.     With Sheets("Sheet1")
  26.         For Each E In .Range("C3", .[C3].End(xlDown))
  27.             If D.EXISTS(E.Value) Then
  28.                  E.Offset(, 9) = D(E.Value)(0)
  29.                  E.Offset(, 10) = D(E.Value)(1)
  30.             Else
  31.                 E.Offset(, 9) = "No received"
  32.                 E.Offset(, 10) = ""
  33.             End If
  34.             
  35.         Next
  36.     End With
  37. End Sub
複製代碼

TOP

回復 4# john2006168
Dictionary 物件  D(Key->關鍵字) = Item ->對應項目
D(E.Value) = Array(E.Offset(, -3), E.Offset(, -4))
D(E.Value)(0) = Array(0)
D(E.Value)(1) = Array(1)

TOP

        靜思自在 : 一個缺口的杯子,如果換一個角度看它,它仍然是圓的。
返回列表 上一主題