返回列表 上一主題 發帖

[發問] 資料重複但只顯示出一次

回復 1# g93353
  1. Sub XX()
  2. Set d = CreateObject("scripting.dictionary")
  3. For Each A In Range([A1], [A1].End(xlDown))
  4.   d(A.Value) = ""
  5. Next
  6. Cells(1, "B").Resize(d.Count, 1) = Application.Transpose(d.keys)
  7. Cells(1 + d.Count, "B") = "共" & d.Count & "人"
  8. End Sub
複製代碼

TOP

回復 3# g93353
  1. Sub YY()
  2. Set d = CreateObject("scripting.dictionary")
  3. n = Application.Match("總數", Columns("A"), 0)
  4. For Each A In Range("A1:A" & n - 2)
  5.   If A.Value <> "" Then d(A.Value) = ""
  6. Next
  7. If d.Count <> 0 Then Cells(1, "B").Resize(d.Count, 1) = Application.Transpose(d.keys)
  8. Cells(n - 1, "A") = "共" & d.Count & "人"
  9. Cells(1 + d.Count, "B") = "共" & d.Count & "人"
  10. End Sub
複製代碼

TOP

回復 5# g93353

Cells(1, "B").Resize(d.Count, 1) = Application.Transpose(d.keys)

d.Count                                         字典內關鍵字的數目(數字)
d.keys                                           字典內的關鍵字(橫向陣列)
Cells(1, "B")=Range("A1")=[A1]     儲存格A1
Cells(1, "B").Resize(d.Count, 1)      將儲存格A1之範圍擴大為d.Count列1欄
Application.Transpose(d.keys)         將字典內的關鍵字(橫向陣列)轉置為直向陣列

TOP

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