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

Scripting.DictionaryªºÀ³¥Î

Scripting.DictionaryªºÀ³¥Î

³o¨â¤Ñ¦b¬Ý¦r¨åªºÀ³¥Î,¦r¨å¹ï¶Hªº¤èªk¦³6­Ó¡GAdd¤èªk¡BKeys¤èªk¡BItems¤èªk¡BExists¤èªk¡BRemove¤èªk¡BRemoveAll¤èªk¡C
ªþ¥ó¤@­Ótest filr ·Q¬Ý¬Ý¦Ñ®v«ç¼g?©M¥Î¨ì¤W­±ªº­þ´X­Ó¤èªk

Â^¨ú2.PNG (19.01 KB)

Â^¨ú2.PNG

TEST2.zip (8.17 KB)

ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
«á¾ÇÂǦ¹©«½m²ß°}¦C»P¦r¨å,¾Ç²ß¤è®×¦p¤U,½Ð¦U¦ì«e½ú«ü±Ð

¸ê®Æªí:


µ²ªGªí°õ¦æ«e:


°õ¦æµ²ªG:



Option Explicit
Sub TEST_1()
Dim Brr, Crr, Z, i&, j%, R&, Y&, T$
Set Z = CreateObject("Scripting.Dictionary")
Brr = Range([¤u§@ªí1!D1], [¤u§@ªí1!A65536].End(3))
ReDim Crr(1 To UBound(Brr), 1 To 3)
For i = 1 To UBound(Brr)
   T = Brr(i, 2) & "|" & Brr(i, 4)
   R = Z(T)
   If R = 0 Then
      Y = Y + 1: R = Y
      For j = 1 To 3: Crr(R, j) = Brr(i, j + 1): Next
      Z(T) = R: GoTo i01
   End If
   Crr(R, 2) = Crr(R, 2) + Brr(i, 3)
i01: Next
With [Summary!A1].Resize(Y, 3)
   .EntireColumn.ClearContents
   .Value = Crr
End With
Set Z = Nothing: Erase Brr, Crr
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 10# samwang

ÁÂÁ±z¸ÑÄÀ.

TOP

¦^´_ 9# john2006168

¸ÑÄÀ¼g±o¤£¦n®É¡A½Ð¨£½Ì¡A·PÁ¡C

Sub test()
Dim Arr, xD, T, T2, T3, T4, i&, M%, N%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Sheets("¤u§@ªí1").[A1].CurrentRegion '¸ê®Æ¸Ë¤J¼Æ²Õ
For i = 1 To UBound(Arr)
     T = Arr(i, 2) & "|" & Arr(i, 4)    'ÃöÁä±ø¥ó¦ê³s¤@°_·í§@key
     T2 = Arr(i, 2): T3 = Arr(i, 3): T4 = Arr(i, 4)
     If xD.Exists(T & "") Then          'key¦³µL¦b¦r¨å
         M = xD(T & "")                      '§ä¨ì¦Pkeyªº¦ì¸m
         Arr(M, 2) = Arr(M, 2) + T3  '²Ö¥[
     Else
         N = N + 1: xD(T & "") = N  'key¸Ë¤J¦r¨å¥B½s¬y¤ô¸¹
         Arr(N, 1) = T2: Arr(N, 2) = T3: Arr(N, 3) = T4 '±N²Å¦X±ø¥óªº¸ê®Æ¸Ë¨ìµ²ªGªº¼Æ²Õ
     End If
Next
Sheets("Summary").[A1].Resize(N, 3) = Arr  'µ²ªGÅã¥Ü
End Sub

TOP

¦^´_ 8# samwang
¥i¥H¹B¦æ,¦ý¬O¦³¨Ç¦a¤è¤£¬O«Ü²z¸Ñ,¥i§_À°¦£µùÄÀ¤@¤U.

TOP

¦^´_ 7# john2006168

½Ð´ú¸Õ¬Ý¬Ý¡A±ø¥ó½ÆÂø®É¡A¥i¥H¨Ï¥Î¦r¨å+¼Æ²Õ°}¦C¤ñ¸û®e©ö¸Ñ¡AÁÂÁ¡C

Sub test()
Dim Arr, xD, T, T2, T3, T4, i&, M%, N%
Set xD = CreateObject("Scripting.Dictionary")
Arr = Sheets("¤u§@ªí1").[A1].CurrentRegion
For i = 1 To UBound(Arr)
    T = Arr(i, 2) & "|" & Arr(i, 4)
    T2 = Arr(i, 2): T3 = Arr(i, 3): T4 = Arr(i, 4)
    If xD.Exists(T & "") Then
        M = xD(T & ""): Arr(M, 2) = Arr(M, 2) + T3
    Else
        N = N + 1: xD(T & "") = N
        Arr(N, 1) = T2: Arr(N, 2) = T3: Arr(N, 3) = T4
    End If
Next
Sheets("Summary").[A1].Resize(N, 3) = Arr
End Sub

TOP

¦^´_ 6# samwang

samwang,½Ð°Ý¤@¤U¦pªG§Ú¥[¦h¤@Äæ©M¦h¤@­Ó±ø¥ó,¬Û¦Pªº"LOCATION"¥[¦b¤@°_,½Ð°Ý³o¼Ë«ç»ò¼g.

Â^¨ú.PNG (7.86 KB)

Â^¨ú.PNG

TEST2.zip (12.73 KB)

TOP

¦^´_ 5# john2006168

¤£¦n·N«ä4¼Ó¡AT3¶·§ï¬°T2   
xD(T & "") = xD(T & "") + T2   ' Name¦³­«½Æ®É¡AOder ¼Æ­È²Ö¥[

TOP

¦^´_ 3# samwang

ÁÂÁ´£¨Ñ¨âºØ¤èªk,ºCºC¾Ç²ß¤¤.
½Ð°Ý¥i§_À°¦£¸ÑÄÀ³o¥y·N«ä?
    xD(T & "") = xD(T & "") + T2

TOP

§ó·s#3¼Ó¡A©ñ¤F±NªíÀY²Ä¤@¦C¤]¥i¥H¼g¤J¦r¨å§Y¥i¡AÁÂÁ¡C
Sub test3()
Dim Arr, xD, T, T2, i&
Set xD = CreateObject("Scripting.Dictionary")
Arr = Sheets("¤u§@ªí1").[A1].CurrentRegion
For i = 1 To UBound(Arr)
    T = Arr(i, 2): T2 = Arr(i, 3)
    xD(T & "") = xD(T & "")
    xD(T & "") = xD(T & "") + T3
Next
Sheets("Summary").[A1].Resize(xD.Count) = Application.Transpose(xD.keys)
Sheets("Summary").[B1].Resize(xD.Count) = Application.Transpose(xD.items)
End Sub

TOP

        ÀR«ä¦Û¦b : Ãø¦æ¯à¦æ¡AÃø±Ë¯à±Ë¡AÃø¬°¯à¬°¡A¤~¯àª@µØ¦Û§Úªº¤H®æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD