- ©«¤l
- 4901
- ¥DÃD
- 44
- ºëµØ
- 24
- ¿n¤À
- 4916
- ÂI¦W
- 43
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 20xx
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥x¥_
- µù¥U®É¶¡
- 2010-4-30
- ³Ì«áµn¿ý
- 2025-2-19
               
|
[Âà¶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¤@©wn¥Î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
« ³Ì«á½s¿è®É¶¡: 2005-04-03, 21:18:05 ¥Ñ leonchou »
http://gb.twbts.com/index.php?topic=510.0 |
|