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

[µo°Ý] ½Ð±Ð­n¦p¦ó¨Ï¥Î VBA §P§O¤£³W«hÀx¦s®æªº¿ìªk2

¦^´_ 29# ML089
ÁÂÁ§A¸ÔºÉªº»¡©ú¡A­è¤~§Ú¤w¥þ³¡¨Ï¥Î Debug ¶]¤F¤@°é¡A
¤£©úÁA³B¥ç¤w¥ÑDebug¤¤±o¨ìµª®×¡A¦¹µ{¦¡À³¥Î°}¦C³B²z
¥ç±Æ°£¤F­ì¥ý°õ¦æ³t«×¿ð½wªº§xÂZ¡AÁÂÁ§AªºÀ°¦£¡I

TOP

¦^´_ 31# c_c_lai

¬Q¤Ñ¬O¥ÎÀx¦s®æ¤è¦¡³B²z¡A¤j­P»Ý­n3¤ÀÄÁ¡A¦­¤W§ï¬°°}¦C³B²z¬ù»Ý­n10¬íÄÁ¡A¦A¶i¦æÀu¤Æ¥i¹F2¡ã3¬íÄÁ
¥i¨£Àx¦s®æ»P°}¦C³B²z³t«×¬Û®t20­¿¥H¤W
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 32# ML089
¸Õ¸Õ¸g­×§ï«á¤§µ{¦¡¡G

­±¿n¤j¤p¤À§G²Î­p_ML089.rar (150.15 KB)

TOP

¦^´_ 32# ML089
§ó¥¿¹Ï¤ù¡A¤WÀYªº¬O¦b Debug Mode¡A ©Ò¥H®É¶¡¸ûªø¡A
§ó¥¿«á¤§¹Ï¤ù¬°½T¹ê°õ¦æ¬í¼Æ¡C

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2013-12-7 20:51 ½s¿è

¦^´_ 32# ML089
¼W­×«á¤§µ{¦¡½X¦p¤U¡G
  1. Option Explicit

  2. '  ML089 ¼g©ó 2013/12/7
  3. '  http://forum.twbts.com/viewthread.php?tid=10927&extra=&page=3
  4. Sub ³sÄò0­Ó¼Æ¤§²Î­p()
  5.     Dim dic As Object
  6.     Dim t1 As Date, tt1 As Date, t2 As Date, tt2 As Date
  7.     Dim Arr As Variant, xDebug As String, sRng As Range, WriteToRange As Range
  8.     Dim i As Integer, c As Long, r As Long, y As Integer, rN As Long, cN As Long
  9.     Dim Bins_array As Variant, ArrF As Variant, ArrN As Variant, MaxN As Double
  10.    
  11.     Application.Calculation = xlManual    '  Ãö³¬­pºâ
  12.     Application.ScreenUpdating = False    '  Ãö³¬Åã¥Ü

  13.     xDebug = InputBox("°}¦C­pºâ¸ê®Æ¼g¥X¡C¶ñ¤J 1 / 0 ±±¨î :", "DeBug", 0) '  ¡·°}¦C­pºâ¸ê®Æ¼g¥X¡C¶ñ¤J 1¡BTure / 0¡BFlase ±±¨î
  14.     If xDebug Then ActiveSheet.Copy after:=ActiveSheet    '  Test Use 1

  15.     t1 = Timer: tt1 = Time    '  ¬í¼Æ­p®É¾¹
  16.     Set dic = CreateObject("Scripting.Dictionary")
  17.     dic("³sÄò¦ì§}") = "²Õ¦X¼Æ¶q"

  18.     '  ¡õ §ä 0¡A±N¨C²Õ³sÄò 0 ½s¤£¦P§Ç¸¹
  19.     '  Arr : Variant/Variant(1 to 20, 1 to 26)
  20.     Arr = ActiveSheet.[A1].CurrentRegion    '  Åª¤J°}¦C
  21.    
  22.     i = 0
  23.     rN = UBound(Arr, 1)     '  Y  Rows     20
  24.     cN = UBound(Arr, 2)     '  X  Columns  26
  25.    
  26.     For c = 1 To cN
  27.         For r = 1 To rN     '  ¦¹°j°é±N°}¦C«D0­È§ï¬°¤å¦r«¬ºA
  28.             If Arr(r, c) <> 0 Then Arr(r, c) = "X" '  Empty ·|³Qµø¬° 0¡A"" ¤£·|
  29.         Next
  30.     Next
  31.     For c = 1 To cN
  32.         For r = 1 To rN    '  ¦¹°j°é§ä 0
  33.             If Arr(r, c) = 0 Then
  34.                 i = i + 1
  35.                 Set sRng = Sheets("TEST2").Cells(r, c)
  36.                 Call xRep(Arr, r, c, i, sRng)
  37.                 dic(sRng.Address) = Range(sRng.Address).Count
  38.             End If
  39.         Next
  40.     Next

  41.     If xDebug Then [A1].Resize(rN, cN) = Arr    '  Test Use 2    ' i = 11

  42.     '  ¡õ ­pºâ¨C²Õ­Ó¼Æ¡C ª`·N! Frequency ¦^¶Ç i + 1 ²Õ¡A©Ò¥ý±N i - 1
  43.     Bins_array = Application.Evaluate("Row(1:" & i - 1 & ")")   ' i = 11
  44.     '  ­pºâ¬Y¤@­Ó½d³ò¤ºªº­È¥X²{ªº¦¸¼Æ¡A¨Ã¶Ç¦^¤@­Ó««ª½¼Æ­È°}¦C¡C
  45.     '  ¨Ò¦p¡A¥Î FREQUENCY ¨Ó­pºâ¬Y¨Ç½d³ò¤ºªº¦Ò¸Õ¦¨ÁZ¦U¦³´X­Ó¤H¡C
  46.     '  ¥Ñ©ó FREQUENCY ¶Ç¦^°}¦C¡A¦]¦¹¥²¶·¿é¤J¬°°}¦C¤½¦¡¡C
  47.     ArrN = Application.Frequency(Arr, Bins_array)
  48.     MaxN = Application.Max(ArrN)   '  MaxN : 62 : Variant/Double  (¥H¤W²Î­p¼Æªº³Ì¤j­È)

  49.     '  ¡õ ²Î­p¨C²Õ­Ó¼Æ¡C ª`·N! Frequency ¦^¶Ç i + 1 ²Õ¡A©Ò¥ý±N MaxN - 1
  50.     Bins_array = Application.Evaluate("Row(1:" & MaxN - 1 & ")")
  51.     ArrF = Application.Frequency(ArrN, Bins_array)

  52.     '  ¡õ ¼g¥X¸ê®Æ
  53.     Set WriteToRange = ActiveSheet.Cells(rN + 3, 1)
  54.     WriteToRange.CurrentRegion.ClearContents
  55.     Application.Goto Reference:=WriteToRange, scroll:=True   ' ±Nµe­±¤Á´«¦Ü WriteToRange¡C
  56.     With WriteToRange
  57.         .Resize([A:A].Rows.Count - rN - 3, 2) = ""
  58.         .Resize(1, 2) = Application.Evaluate("{""³sÄò¼Æ"", "";²Õ¼Æ""}")
  59.         y = 0
  60.         For i = 1 To MaxN
  61.             If ArrF(i, 1) <> 0 Then
  62.                 y = y + 1
  63.                 .Offset(y, 0) = i
  64.                 .Offset(y, 1) = ArrF(i, 1)
  65.             End If
  66.         Next
  67.         .Offset(0, 2).Resize(dic.Count, 1) = Application.Transpose(dic.keys)
  68.         .Offset(0, 3).Resize(dic.Count, 1) = Application.Transpose(dic.items)
  69.          
  70.         t2 = Timer: .Offset(y + 1, 1) = Format(t2 - t1, "0.00") & " ¬í"
  71.         tt2 = Time: .Offset(y + 2, 1) = Format((tt2 - tt1) * 24 * 60 * 60, "0.00") & " ¬í"
  72.     End With
  73.     Set Arr = Nothing       '  ÄÀ©ñ°O¾ÐÅé
  74.     Set dic = Nothing
  75.    
  76.     Application.ScreenUpdating = True
  77.     Application.Calculation = xlCalculationAutomatic
  78. End Sub

  79. '  »¼°j©I¥s( recursive call )¬d¸ß¡A±N³sÄò0¼g¤J¦P¤@½s¸¹
  80. Sub xRep(ByRef Arr, r, c, i, ByRef rng As Range)
  81.     Dim Temp As Range
  82.    
  83.     Arr(r, c) = i    '  ¼g¤J½s¸¹
  84.     Cells(r, c).Interior.ColorIndex = 6    '  Test Use 3
  85.     Set Temp = Union(rng, Sheets("TEST2").Cells(r, c))
  86.     On Error Resume Next    '  ÁקKÃä¬É¿ù»~
  87.     If Arr(r - 1, c) = 0 Then Call xRep(Arr, r - 1, c, i, Temp)    '  §ä¤W
  88.     If Arr(r + 1, c) = 0 Then Call xRep(Arr, r + 1, c, i, Temp)    '  §ä¤U
  89.     If Arr(r, c - 1) = 0 Then Call xRep(Arr, r, c - 1, i, Temp)    '  §ä¥ª
  90.     If Arr(r, c + 1) = 0 Then Call xRep(Arr, r, c + 1, i, Temp)    '  §ä¥k
  91.     Set rng = Temp
  92. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : §Ñ¥\¤£§Ñ¹L¡A§Ñ«è¤£§Ñ®¦¡C
ªð¦^¦Cªí ¤W¤@¥DÃD