- ©«¤l
- 2035
- ¥DÃD
- 24
- ºëµØ
- 0
- ¿n¤À
- 2031
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Office2010
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-3-22
- ³Ì«áµn¿ý
- 2024-2-1
|
¥»©«³Ì«á¥Ñ c_c_lai ©ó 2013-12-7 20:51 ½s¿è
¦^´_ 32# ML089
¼W׫ᤧµ{¦¡½X¦p¤U¡G- Option Explicit
- ' ML089 ¼g©ó 2013/12/7
- ' http://forum.twbts.com/viewthread.php?tid=10927&extra=&page=3
- Sub ³sÄò0ӼƤ§²Îp()
- Dim dic As Object
- Dim t1 As Date, tt1 As Date, t2 As Date, tt2 As Date
- Dim Arr As Variant, xDebug As String, sRng As Range, WriteToRange As Range
- Dim i As Integer, c As Long, r As Long, y As Integer, rN As Long, cN As Long
- Dim Bins_array As Variant, ArrF As Variant, ArrN As Variant, MaxN As Double
-
- Application.Calculation = xlManual ' Ãö³¬pºâ
- Application.ScreenUpdating = False ' Ãö³¬Åã¥Ü
- xDebug = InputBox("°}¦Cpºâ¸ê®Æ¼g¥X¡C¶ñ¤J 1 / 0 ±±¨î :", "DeBug", 0) ' ¡·°}¦Cpºâ¸ê®Æ¼g¥X¡C¶ñ¤J 1¡BTure / 0¡BFlase ±±¨î
- If xDebug Then ActiveSheet.Copy after:=ActiveSheet ' Test Use 1
- t1 = Timer: tt1 = Time ' ¬í¼Æp®É¾¹
- Set dic = CreateObject("Scripting.Dictionary")
- dic("³sÄò¦ì§}") = "²Õ¦X¼Æ¶q"
- ' ¡õ §ä 0¡A±N¨C²Õ³sÄò 0 ½s¤£¦P§Ç¸¹
- ' Arr : Variant/Variant(1 to 20, 1 to 26)
- Arr = ActiveSheet.[A1].CurrentRegion ' Ū¤J°}¦C
-
- i = 0
- rN = UBound(Arr, 1) ' Y Rows 20
- cN = UBound(Arr, 2) ' X Columns 26
-
- For c = 1 To cN
- For r = 1 To rN ' ¦¹°j°é±N°}¦C«D0ȧאּ¤å¦r«¬ºA
- If Arr(r, c) <> 0 Then Arr(r, c) = "X" ' Empty ·|³Qµø¬° 0¡A"" ¤£·|
- Next
- Next
- For c = 1 To cN
- For r = 1 To rN ' ¦¹°j°é§ä 0
- If Arr(r, c) = 0 Then
- i = i + 1
- Set sRng = Sheets("TEST2").Cells(r, c)
- Call xRep(Arr, r, c, i, sRng)
- dic(sRng.Address) = Range(sRng.Address).Count
- End If
- Next
- Next
- If xDebug Then [A1].Resize(rN, cN) = Arr ' Test Use 2 ' i = 11
- ' ¡õ pºâ¨C²ÕӼơC ª`·N! Frequency ¦^¶Ç i + 1 ²Õ¡A©Ò¥ý±N i - 1
- Bins_array = Application.Evaluate("Row(1:" & i - 1 & ")") ' i = 11
- ' pºâ¬Y¤@Ó½d³ò¤ºªºÈ¥X²{ªº¦¸¼Æ¡A¨Ã¶Ç¦^¤@Ó««ª½¼ÆÈ°}¦C¡C
- ' ¨Ò¦p¡A¥Î FREQUENCY ¨Ópºâ¬Y¨Ç½d³ò¤ºªº¦Ò¸Õ¦¨ÁZ¦U¦³´XÓ¤H¡C
- ' ¥Ñ©ó FREQUENCY ¶Ç¦^°}¦C¡A¦]¦¹¥²¶·¿é¤J¬°°}¦C¤½¦¡¡C
- ArrN = Application.Frequency(Arr, Bins_array)
- MaxN = Application.Max(ArrN) ' MaxN : 62 : Variant/Double (¥H¤W²Îp¼Æªº³Ì¤jÈ)
- ' ¡õ ²Îp¨C²ÕӼơC ª`·N! Frequency ¦^¶Ç i + 1 ²Õ¡A©Ò¥ý±N MaxN - 1
- Bins_array = Application.Evaluate("Row(1:" & MaxN - 1 & ")")
- ArrF = Application.Frequency(ArrN, Bins_array)
- ' ¡õ ¼g¥X¸ê®Æ
- Set WriteToRange = ActiveSheet.Cells(rN + 3, 1)
- WriteToRange.CurrentRegion.ClearContents
- Application.Goto Reference:=WriteToRange, scroll:=True ' ±Nµe±¤Á´«¦Ü WriteToRange¡C
- With WriteToRange
- .Resize([A:A].Rows.Count - rN - 3, 2) = ""
- .Resize(1, 2) = Application.Evaluate("{""³sÄò¼Æ"", "";²Õ¼Æ""}")
- y = 0
- For i = 1 To MaxN
- If ArrF(i, 1) <> 0 Then
- y = y + 1
- .Offset(y, 0) = i
- .Offset(y, 1) = ArrF(i, 1)
- End If
- Next
- .Offset(0, 2).Resize(dic.Count, 1) = Application.Transpose(dic.keys)
- .Offset(0, 3).Resize(dic.Count, 1) = Application.Transpose(dic.items)
-
- t2 = Timer: .Offset(y + 1, 1) = Format(t2 - t1, "0.00") & " ’"
- tt2 = Time: .Offset(y + 2, 1) = Format((tt2 - tt1) * 24 * 60 * 60, "0.00") & " ’"
- End With
- Set Arr = Nothing ' ÄÀ©ñ°O¾ÐÅé
- Set dic = Nothing
-
- Application.ScreenUpdating = True
- Application.Calculation = xlCalculationAutomatic
- End Sub
- ' »¼°j©I¥s( recursive call )¬d¸ß¡A±N³sÄò0¼g¤J¦P¤@½s¸¹
- Sub xRep(ByRef Arr, r, c, i, ByRef rng As Range)
- Dim Temp As Range
-
- Arr(r, c) = i ' ¼g¤J½s¸¹
- Cells(r, c).Interior.ColorIndex = 6 ' Test Use 3
- Set Temp = Union(rng, Sheets("TEST2").Cells(r, c))
- On Error Resume Next ' ÁקKÃä¬É¿ù»~
- If Arr(r - 1, c) = 0 Then Call xRep(Arr, r - 1, c, i, Temp) ' §ä¤W
- If Arr(r + 1, c) = 0 Then Call xRep(Arr, r + 1, c, i, Temp) ' §ä¤U
- If Arr(r, c - 1) = 0 Then Call xRep(Arr, r, c - 1, i, Temp) ' §ä¥ª
- If Arr(r, c + 1) = 0 Then Call xRep(Arr, r, c + 1, i, Temp) ' §ä¥k
- Set rng = Temp
- End Sub
½Æ»s¥N½X |
|