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

[µo°Ý] ¸ê®Æ³B²z-§ä¥X°ß¤@ªº¸ê®Æ

[µo°Ý] ¸ê®Æ³B²z-§ä¥X°ß¤@ªº¸ê®Æ

¥»©«³Ì«á¥Ñ hugh0620 ©ó 2012-3-26 10:35 ½s¿è

Dear ¤j¤j­Ì
          ¤p§Ì¸g±`»Ý­n¹ï­«ÂЦhµ§¼Æ¾Ú±N¨ä¿@ÁY¦¨°ß¤@ªº¸ê®Æ~
          ¦b³o­Ó³B²z¤W,°ò¥»ªº§@ªk³£¬O±Ä¥Î[¶i¶¥¿z¿ï]ªº¤è¦¡,¥ý±N¸ê®Æ³B²z¦¨°ß¤@«á,
          ¦A¶i¦æ«áÄò¥[¤u¦¨¬°»Ý­nªºµ²ªG~
          ³Ì¦h³B²zªº¬O¨âÄ檺¸ê®Æ,¦pªþÀɤΤU¹Ï
          ¨Ìdata A¬°¥D,±N²Å¦Xdata Aªºdata B¸ê®Æ§ä¥X¨Ó~
          ¹³³o¼Ëªº¸ê®Æ,§Úªº³B²z¤è¦¡¤j·§¦p¤U
          1. [¶i¶¥¿z¿ï]ABÄæ¦ì,¿ï¾Ü¤£­«ÂÐ
          2. [¶i¶¥¿z¿ï]ªºµ²ªG,¦A¥Î°j°é+IF§PÂ_±o¨ì³Ì«áªºµ²ªG
          ©ß¥X³o­Ó°ÝÃD,½Ð¤j¤j¦³±Ð©ó§Ú

¸ê®Æ³B²z.rar (10.72 KB)
¾Ç²ß¤~¯à´£¤É¦Û¤v

¦^´_ 1# hugh0620
  1. Sub Ex()
  2. Set d = CreateObject("Scripting.Dictionary")
  3. ar = Range("A1").CurrentRegion.Value
  4. For i = 1 To UBound(ar, 1)
  5.   If d(ar(i, 1)) = "" Then
  6.      d(ar(i, 1)) = ar(i, 2)
  7.      ElseIf InStr(d(ar(i, 1)), ar(i, 2)) = 0 Then
  8.      d(ar(i, 1)) = d(ar(i, 1)) & "/" & ar(i, 2)
  9.   End If
  10. Next
  11. [J:K] = ""
  12. [J1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  13. [K1].Resize(d.Count, 1) = Application.Transpose(d.items)
  14. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 2# Hsieh

Hsieh ¤j¤j~ «Ü·PÁ§Aªº¦^ÂÐ~
³o´N¬O§Ú·Q­n¤F¸Ñ¤Î·Q­n§ó²`¤J¾Ç²ß¨ÓÀ³¥Îªº»yªk~
¥i¥H²q±o¥X¾ã­Ó¼¶¼gªºÅÞ¿è,¦ý¤£²M·¡¤@¨Ç»yªkªº¨Ï¥Î¤è¦¡~
½Ð¤j¤j¯à¸ÑÄÀ¤@¤U~ À°¤p§Ì¸Ñ´b¤@¤U
  1. Sub Ex()

  2. Set d = CreateObject("Scripting.Dictionary")
  3. '°ÝÃDCreateObject:«Ø¥ß¨Ã¶Ç¦^¹ï©ó ActiveX ª«¥óªº¤Þ¥Î¡C
  4. '["Scripting.Dictionary"]<==³o¬O¤°»ò·N«ä©O??
  5. '¦]¬°¤j¤j¦³¨Ç®É­Ô¥Îªº¤è¦¡¡A«öF1¬O¬d¤£¨ìªº

  6. ar = Range("A1").CurrentRegion.Value
  7. 'CurrentRegion:¶Ç¦^ Range ª«¥ó¡A¸Óª«¥ó¥Nªí¥Ø«eªº°Ï°ì¡C¥Ø«e°Ï°ì¬O«ü¥H¥ô·NªÅ¥Õ¦C¤ÎªÅ¥ÕÄ檺²Õ¦X¬°Ãä¬Éªº½d³ò¡C
  8. '¤p§Ì²qar¬O§_¬°¥ÑA1¶}©l¨ìªÅ¥ÕÃä¬ÉªºÀx¦s®æ½d³ò

  9. For i = 1 To UBound(ar, 1)
  10. 'UBound:ªí¥Ü«ü©w°}¦C¬Yºû³Ì¤j¥i¨Ï¥Îªº°}¦C¯Á¤Þ¡C
  11. '¥ÎUBound¨Ó§ì¨úar½d³ò¤@ºûªº³Ì¤j°}¦C¯Á¤Þ¡C

  12.   If d(ar(i, 1)) = "" Then
  13. 'd ¬O²Ä¤@¥ySet d = CreateObject("Scripting.Dictionary")¤¤ªºd¡A¦ý¤£¤F¸Ñ«ç»ò¸ÑŪ¡C
  14.      d(ar(i, 1)) = ar(i, 2)
  15.      ElseIf InStr(d(ar(i, 1)), ar(i, 2)) = 0 Then
  16. 'InStr¬O¥Î¨Ó¤ñ¹ïd(ar(i, 1)), ar(i, 2)¬O§_¦³¤@¼Ëªº¸ê®Æ¡A­Y¨S¦³¤@¼Ë«hshow0,0=0´N¬Oªí¥Üar(i, 2)¬O­n·s¼Wªº
  17.      d(ar(i, 1)) = d(ar(i, 1)) & "/" & ar(i, 2)
  18.   End If
  19. Next
  20. [J:K] = ""
  21. [J1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  22. [K1].Resize(d.Count, 1) = Application.Transpose(d.items)
  23. 'Application.Transpose(d.keys)»PApplication.Transpose(d.items) ´N¤@ÂIÀYºü¤]¨S¦³¡A¤£ª¾¹D«ç»ò¨Ï¥Î??
  24. End Sub
½Æ»s¥N½X
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

¦^´_ 3# hugh0620
»{ÃÑDictionary   
VBA»¡©úÀɽХÑFileSystemObject ª«¥ó»¡©ú¤¤ªº¡i½Ð°Ñ¾\¡j¤¤·j´M

Application.Transpose(d.keys)»PApplication.Transpose(d.items)³o¥u¬O±N¦r¨åª«¥óªº¯Á¤Þ°}¦C»P¤º®e°}¦CÂà¸m
¦r¨åª«¥ó¥i¥Î¤ñ¸û²³æªº·§©À¨Ó²z¸Ñ
ª«¥ó¤¤·|¦s¦b2­Ó°}¦Ckeys¡Aitems
keys¬OÀx¦sÃöÁä¦rªº°}¦C
items¬O¹ïÀ³ÃöÁä¦rªº¤º®e°}¦C
¨C¤@­Ókey·|¹ïÀ³¤@­Óitem
³o¨â­Ó°}¦C¦s¦b¬O¾î¦V±Æ¦C¡A©Ò¥H¡A·í­n¼g¤JÀx¦s®æ®É¡A¥²¶·Âন»PÀx¦s®æ¦P¦Vªº°}¦C
­Y¥Hª«¥óªºadd¤èªk¥[¤J¤¸¯À®É¡A¦pªGÃöÁä¦r(key)­«½Æ®É·|²£¥Í¿ù»~¡A¥²¶·¥ýÀˬd¬O§_¤w¸g¦s¦b¸Ó¶µ¥Ø(³o­Ó¯S©Ê¥Î¨Ó¨ú±o¤£­«½Æ²M³æ)
¨Ï¥Îdiction(key)=item³o¼Ëªº¤è¦¡¥[¤J¶µ¥Ø¡A·|¥H«á¨Óªºitem¨ú¥N­ì¥ý ªºitem
­Y¦³¥ô¦ó°ÝÃD¡AÅwªï´£¥X°Q½×¡A¤]½Ð¹ï¦¹ª«¥ó¼ô±xªºªB¤Í¥[¤J°Q½×
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 4# Hsieh


    Hsieh ¤j¤j~ ³o­ÓªF¦è¤ñ¸û©â¶H¤@¨Ç~ ­nªáÂI®É¶¡¨Ó®ø¤Æ¤@¤U~
    ¤p§Ì¦A±N²z¸Ñªºµ²ªG~ ¤À¨É¤@¤U~ ¦A½Ð¤j¤j«ü¥¿¤@¤U~
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

¦^´_ 3# hugh0620
'["Scripting.Dictionary"]<==³o¬O¤°»ò·N«ä©O??,'¦]¬°¤j¤j¦³¨Ç®É­Ô¥Îªº¤è¦¡¡A«öF1¬O¬d¤£¨ìªº
Dictionary ª«¥ó ->¦r¨åª«¥ó : ´N¹³¬d¦r¨å ,¬d¨ì¤@­ÓÃöÁä¦r(Key)«á¦³¬Û¹ïªº»¡©ú (Item)
Key  ¸ÓÃöÁä¦r¥Î¨Ó¨ú¥X³æ­Ó¶µ¥Ø¡A³q±`¬O¾ã¼Æ©Î¦r¦ê¡A¥i¥H¬O°£°}¦C¥~ªº¥ô¦ó«¬ºA¡C
Item  ¥i¥H¬O¥ô¦ó«¬ºAªº

¬d¬Ý Dictionary ª«¥ó ªº»¡©ú ¦p¹Ï

TOP

¦^´_ 6# GBKEE


    ÁÂÁÂG¤j¤j~ ±Ð¾É~ ¤p§Ì·|¦n¦n²z¸Ñªº~
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

¦^´_ 4# Hsieh

   Hsieh ¤j¤j~ «ÜÁÂÁ§Aªº«ü¾É~
   ¥J²Óªº¥h¤F¸ÑDictionaryªº»¡©ú»P±zªºµ{¦¡½X~
   ¦bÀ³¥Î¤W¨ü¯q¨}¦h~  ¦b¨â­Ó¤ñ¹ï¤WªºÀ³¥Î¤£¥Î¹³¥H«e­n¦h¦¸¿z¿ï«á~ ¤~¯à§¹¦¨~

   ¤p§Ì¥ç°w¹ï¦b¤ñ¹ï¤W¦A´£¥X¤@¨Ç°ÝÃD,½Ð¤j¤j­Ì¦A¦³±Ð©ó§Ú
   Dictionary ¦b³B²zªº¬O¤Gºûªº¤ñ¹ï~ ¥ç¬J¬O¨â¨â¤ñ¸û~
   ­Y¬O·Q­n¤ñ¹ï3~N­Ó¶µ¥Øªº¸Ü~ ¤j¤j¬O§_¦³¨ä¥L§ó¦nªº³B²z¤è¦¡~
   ¥i¥H±Ð¾É¤@¤U
  1. a = d.keys
  2. b = d.items
  3. For i = 0 To d.Count - 1
  4.     Range("J" & 1 + i) = a(i)
  5.     Range("K" & 1 + i) = b(i)
  6. Next
  7. '³z¹LDictionaryªº½d¨Ò»¡©ú~ ¥Î¥t¥~¤@ºØ¤ñ¸ûª½Ä±ªºªí¹F¤è¦¡
  8. '»P±z¼gªº¤U­±¨â¦æ¥i¥H¹F¨ì¤@¼Ëªº¥\¯à~
  9. '¤j¤j¼gªº¬O¶i¶¥ªº¥Îªk~ ¤p§Ì³ßÅw©î¦¨¦Û¤v¤ñ¸ûª½Ä±ªº¥Îªk~
  10. '¤£µMµw¬O¥h®M¥Î~ ´N¤ñ¸û¨S¦³¼u©Ê
  11. '[J1].Resize(d.Count, 1) = Application.Transpose(d.keys)
  12. '[K1].Resize(d.Count, 1) = Application.Transpose(d.items)
½Æ»s¥N½X
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

¦^´_ 6# GBKEE

   G¤j¤j~ ¤]»Ý­n½Ð±z¦A«ü±Ð¤@µf~

   ¤p§Ì¥ç°w¹ï¦b¤ñ¹ï¤W¦A´£¥X¤@¨Ç°ÝÃD,½Ð¤j¤j­Ì¦A¦³±Ð©ó§Ú
   Dictionary ¦b³B²zªº¬O¤Gºûªº¤ñ¹ï~ ¥ç¬J¬O¨â¨â¤ñ¸û~
   ­Y¬O·Q­n¤ñ¹ï3~N­Ó¶µ¥Øªº¸Ü~ ¤j¤j¬O§_¦³¨ä¥L§ó¦nªº³B²z¤è¦¡~
   ¥i¥H±Ð¾É¤@¤U
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

¦^´_ 9# hugh0620


    ¦h¶µ¥Ø¤ñ¹ï¡A§Aªº·N«ä¬O»¡¦hÄæ¦ì¬Û¦P¬°¤@­Ó¶µ¥Ø¶Ü?
³o¼Ë¥i¥H§â¦hÄæ¦ì¦r¦ê³s±µ«á·í¦¨ÃöÁä¦r¡A´N¯à¹F¨ì¦hÄæ¦ì¤ñ¹ï
¦Ü©óÀÀ±Nkeys»Pitems¥t¥~¥H°}¦CÅܼÆÂà´«¡A§Ú¤£¥H¬°µM¡A¦]¬°keys»Pitems­ì¥»´N¬O¨â­Ó°}¦C
¥u¬O¦WºÙ¤£¦P½}¤F¡A¥Îªk¬O§_¤ñ¸û¦³¼u©Ê¡AÀ³¸Ó¤]¬Oµø±¡ªp¦Ó©w
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : §g¤l¬°¥Ø¼Ð¡A¤p¤H¬°¥Øªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD