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

[Âà¶K] Dictionaryª«¥óªº»{ÃÑ»PÀ³¥Î

[Âà¶K] Dictionaryª«¥óªº»{ÃÑ»PÀ³¥Î

Dictionaryª«¥ó¥iµø¬°¤@­Ó°}¦C¡AÅý§A©ñ¤J¼Æ¦r©Î¤å¦r¡C
¨º»ò¥¦©M¤@¯ë°}¦C¦³¦ó¤£¦P? Dictionary¹³¤@­Ó¤Gºû°}¦C¡A
¸Ì­±¨C¤@µ§¸ê®Æ¥]§t¯Á¤Þ­È»P¸ê®Æ¤º®e¨â­ÓÄæ¦ì¡F
©ó¬O¥i¥H¤è«Kªº³z¹LDictionaryªºExists¨ç¼Æ¥Î¨ÓÀˬd¤Î¤ñ¹ï¸ê®Æ¡A
¨Ò¦p§A¥i¥Î¨ÓÀˬd¸ê®Æ¬O§_­«ÂСC
Dictionary¤]¾Ö¦³ Add, Remove, RemoveAll... µ¥¤èªk¡A¥i³B²z¨ä¤¤ªº­È¡C

¥H¤Uªº½d¨Ò«Ø¥ß¤@­Ó Dictionaryª«¥ó¡G
Dim nums As Object
Set nums = CreateObject("Scripting.Dictionary")

¥H¤Uªº»yªk§â¸ê®Æ¥[¤J Dictionaryª«¥ó¡G
dictionary_object.Add index, content
¯Á¤Þ­È¥i¥H¬O¼Æ­È©Î¦r¦ê¡C
½d¨Ò¡G
nums.Add Cells(1,1), Cells(1,1)

¥H¤Uªº½d¨ÒÀˬd«ü©w­È¬O§_¦s¦b©ó Dictionaryª«¥ó¡G
If Not nums.Exists(123) Then Msgbox "¤£¦s¦b" Else Msgbox "¦s¦b"

¥i°Ñ¦Ò³o¸Ì¥H±o¨ìDictionary¸û§¹¾ãªº»{ÃÑ --
http://www.officefans.net/cdb/viewthread.php?tid=13039

À³¥Î½d¨Ò
¥H¤U³£¬O¦b¨ä¥L½×¾Â¦^µªªº®×¨Ò¡A©Ò¥H§A¤]³\¦ü´¿¬ÛÃÑ..

½d¨Ò¤@. Àˬd¬Y­È¬O§_¦s¦b©ó¬Y¼Æ¦C¡]Ãþ¦ü¤u§@ªíªº COUNTIF ¨ç¼Æ¡^
Sub check_Num()
¡@Dim nums As Object
¡@Set nums = CreateObject("Scripting.Dictionary")
¡@For Each n In Array(123, 234, 213, 124)
¡@¡@¡@nums.Add n, n
¡@Next
¡@If nums.Exists(222) Then MsgBox "Found!" Else MsgBox "Not Found!"
¡@Set nums = Nothing
End Sub

¤]¥i¥H¼g¦¨¦Û­q¨ç¼Æ¡C

½d¨Ò¤G. Àˬd«ü©wÄ檺­«ÂЭȨä©¥H²M°£ («O¯d³Q²M°£«áªºªÅ®æ)
Sub check_Num()
Dim nums As Object
Set nums = CreateObject("Scripting.Dictionary")
For Each c In Array("A", "C") '³B²zAÄæ¤ÎCÄæ
¡@¡@last_row = Cells(65536, c).End(xlUp).Row
¡@¡@For r = last_row To 1 Step -1
¡@¡@¡@¡@Set cell = Cells(r, c)
¡@¡@¡@¡@If Not nums.Exists(cell.Value) Then
¡@¡@¡@¡@¡@¡@nums.Add cell.Value, cell.Value
¡@¡@¡@¡@Else
¡@¡@¡@¡@¡@¡@cell.ClearContents
¡@¡@¡@¡@End If
¡@¡@Next r
¡@¡@nums.RemoveAll '²¾°£Dictionary¤¤ªº©Ò¦³¸ê®Æ
Next
Set nums = Nothing
End Sub

½d¨Ò¤T. Àˬd¨Ã­ç°£«ü©wÄ檺­«ÂÐ­È (¤£«O¯dªÅ®æ)
Sub check_Num()
Dim nums As Object
Set nums = CreateObject("Scripting.Dictionary")
For Each c In Array("A", "C")
¡@¡@Set cell = Cells(1, c)
¡@¡@While cell <> ""
¡@¡@¡@¡@If Not nums.Exists(cell.Value) Then
¡@¡@¡@¡@¡@¡@nums.Add cell.Value, cell.Value
¡@¡@¡@¡@End If
¡@¡@¡@¡@Set cell = cell.Offset(1, 0)
¡@¡@Wend
¡@¡@Columns(c).ClearContents
¡@¡@r = 1 '±q²Ä1¦C¶}©l¦A¼g¦^Àx¦s®æ
¡@¡@For Each num In nums
¡@¡@¡@¡@Cells(r, c) = num
¡@¡@¡@¡@r = r + 1
¡@¡@Next
¡@¡@nums.RemoveAll
Next
Set nums = Nothing
End Sub

µù¡G
½d¨Ò¤¤ªº»Ý¨D¨Ã«D¤@©w­n¥ÎDictionary¸Ñ¨M¡A½d¨Ò¥u¬O½d¨Ò¡C
¦P¤@­Ó®×¨Ò¥i¯à¦³¦hºØ¸Ñªk¡A¦U¦³Àu¦H¡A¦U¾Ì³ß¦n¡C

¥H¤W»¡©ú¡A¦p¦³¤£¨¬©Î¿ù»~¤§³B¡A·q½Ð«ü¥¿~
¦pªG§A¦³¨ä¥Lªº¬ÛÃöÀ³¥Î¡A¤]Åwªï¤À¨É¡I  

&laquo; ³Ì«á½s¿è®É¶¡: 2005-04-03, 21:18:05 ¥Ñ leonchou &raquo;

http://gb.twbts.com/index.php?topic=510.0

µù¡G
½d¨Ò¤¤ªº»Ý¨D¨Ã«D¤@©w­n¥ÎDictionary¸Ñ¨M¡A½d¨Ò¥u¬O½d¨Ò¡C
¦P¤@­Ó®×¨Ò¥i¯à¦³¦hºØ¸Ñªk¡A¦U¦³Àu¦H¡A¦U¾Ì³ß¦n
Dictionary¬O¦r¨åªº·N«ä
¦pªG¥i¥Î¦b³o¨Ç½d¨Ò¤¤¨C¦¸Åã²{ªºµª®×³£¤£¦P
¬O§_ÁÙ¦³§ó¦n¥i¥H¹B¥Îªº¦a¤è?²¦³º¦r¨å´N¬O¥i¥H¸Ñµª§Ú­Ì«Ü¦h¤£ ª¾ªº³æ¦r©Î¤ù»y
©Ò¥H¤W­zºô¯¸¥~ÁÙ¦³¨ä¥L¾Ç²ßªººô¯¸Åo....¦pªGª©¥D¬O³o­Ó·N«äªº¸Ü!
ÁÂÁÂ!!!

TOP

¦^´_ 2# PD961A


    ³o¤å¯Âºé¬O¸ÑÄÀDictionaryª«¥óªº¥Îªk
´N¹³§A»¡ªº¦P¼Ëªº°ÝÃD¦³¦hºØ¤£¦P¼gªk
§Aª¾¹D¦¹ª«¥ó¯S©Ê«á¤~¯à¶i¤@¨BÀ³¥Î¥L
¦Ü©óÀ³¥Î¨ì­þ?³oºØ°ÝÃD´N¬Ý§A¹J¨ì¦A»¡Åo
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

Dictionaryª«¥ó¥iµø¬°¤@­Ó°}¦C¡AÅý§A©ñ¤J¼Æ¦r©Î¤å¦r¡C
Hsieh µoªí©ó 2010-4-30 23:00

¤]¥i¥H©ñ¤J Range
Sub Ex()
    Dim D As Object, K
    Set D = CreateObject("Scripting.Dictionary")
    D.Add Cells(1, 1), ""
    D.Add Cells(2, 1), ""
    For Each K In D.KEYS
        MsgBox K.Address
    Next
End Sub

TOP

¦³ÃöDictionaryª«¥óªºÀ³¥Î²Ó¸`¥i»¡¬O¤@¨¥ÃøºÉ
§Ú¬Ý¹L³Ì§¹¾ãªº»¡©úÀ³ÄÝžôµoªíªº³o½g¡G
http://www.excelpx.com/thread-145901-1-1.html

TOP

        ÀR«ä¦Û¦b : ¡i°µ¤Hªº¶}©l¡j¨C¤@¤Ñ³£¬O¬G¤Hªº¶}©l¡A¨C¤@­Ó®É¨è³£¬O¦Û¤vªºÄµ±§¡C
ªð¦^¦Cªí ¤W¤@¥DÃD