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

[µo°Ý] ¦p¦ó¨Ï¥ÎVBA©Î¨ç¼Æ°µ¦h­Ó°}¦C¼Æ­Èªº¤ñ¸û¤Î®æ¦¡¤Æ±ø¥óªº³]©w

¦^´_ 8# cmo140497
AUTO_OPEN() Àɮ׶}±Ò®É¦Û°Ê°õ¦æ
  1. Option Explicit
  2. Sub AUTO_OPEN() '¥[¤J®Ö¨ú¤è¶ô'¦]¬°¨S¦³´£¨Ñ¤å¦rÀÉ¡A¥H²{¦³Item§@¬°·s¼W±ø¥ó
  3.     Dim A As Range, K As Integer, i As Integer
  4.     With Sheet1
  5.         .CheckBoxes.Delete
  6.         .Range("B:Z").Interior.ColorIndex = xlNone
  7.         K = Application.CountIf(.Columns("A"), "ID")
  8.         Set A = .Columns("A").Find("ID", lookat:=xlPart)
  9.         For i = 1 To K
  10.         Cells(i + 5, "AA").Select
  11.             With .CheckBoxes.Add(.Cells(i + 5, "AA").Left, .Cells(i + 5, "AA").Top, .Cells(i + 5, "AA").Width, .Cells(i + 5, "AA").Height)
  12.                 .Characters.Text = "Item" & i
  13.                 .Name = "Item" & i
  14.                 .OnAction = "EX"                              'CheckBoxes «ü¥¨¶°ªº µ{¦¡
  15.             End With
  16.             A.Offset(1, 1).Resize(24, 24).Name = "_Item" & i  '¸ê®Æ½d³ò³]¥ß¦WºÙ:¦p¤u§@ªí©w¸q¦WºÙ
  17.             Set A = .Columns("A").FindNext(A)
  18.         Next
  19.         '**  »s©w¦Ê¤À¤ñ ¬° 7 µ¥¤À [S1:Y1] ¦Ê¤À¤ñ¥Ñ¤j¨ì¤p   ***
  20.         For i = 1 To 7  '¦Ê¤À¤ñ¥Ñ¤j¨ì¤p   
  21.             .[AA2].Cells(1, i) = 1 + (1 / 7) - (i / 7)
  22.         Next
  23.     End With
  24. End Sub
  25. Sub EX()   '¤w°õ¦æAUTO_OPEN, «ö¿ïCheckBoxesªºµ{¦¡
  26.     Dim Rng(0 To 25) As Range, S, i
  27.     Dim P As Integer, B As CheckBox, E As Variant
  28.     With Sheet1
  29.          .Range("B:Z").Interior.ColorIndex = xlNone
  30.         For Each B In .CheckBoxes
  31.             If B = 1 Then                                               'CheckBoxe¡F¤Ä¿ï = 1
  32.                 P = P + 1
  33.                 If Not Rng(0) Is Nothing Then
  34.                     Set Rng(0) = Union(Rng(0), .Range("_" & B.Name))
  35.                     For i = 1 To 24                                     '¤w¤Ä¿ï½d³ò¤§ ²Ä1Äæ-²Ä24Äæ
  36.                         For Each E In Rng(0).Areas
  37.                             Set Rng(i) = Union(E.Columns(i), Rng(i))    '¦P¤@Äæ¦ì ³]¬°¦P¤@½d³ò
  38.                         Next
  39.                     Next
  40.                 Else
  41.                     Set Rng(0) = .Range("_" & B.Name)
  42.                     For i = 1 To 24
  43.                         Set Rng(i) = Rng(0).Columns(i)
  44.                     Next
  45.                 End If
  46.             End If
  47.         Next
  48.         If P = 0 Then Exit Sub
  49.         Application.ScreenUpdating = False
  50.         For i = 1 To 24                                     '½d³ò¦³24Äæ
  51.             .Columns(Columns.Count - 1) = ""                '²M°£ ³Ì«á²Ä2Äæ¸ê®Æ
  52.             .Columns(Columns.Count) = ""                    '²M°£ ³Ì«á1Äæ¸ê®Æ
  53.             Rng(i).Copy Cells(1, Columns.Count)             '½Æ»sÄ檺¸ê®Æ
  54.             .Columns(Columns.Count).AdvancedFilter xlFilterCopy, .Cells(1, Columns.Count - 1), Unique:=True
  55.             '¶i¶¥¿z¿ï:¿ï¨ú¤£­«½Æªº¸ê®Æ,´î¤Ö°j°é.
  56.             .Columns(Columns.Count - 1).Sort Key1:=.Cells(1, Columns.Count - 1), Order1:=xlDescending, Header:=xlNo
  57.             '±Æ§Ç : ¤£­nªº¸ê®Æ¸m©ó©³³¡
  58.             Set Rng(25) = .Columns(Columns.Count - 1).Cells(1)   '³]©w­n´M§äªº¦r¦ê
  59.             
  60.             With Rng(i)
  61.                 Do Until Rng(25) = "___" Or Rng(25) = "0" Or Rng(25) = ""
  62.                     Set Rng(0) = .Find(Rng(25), lookat:=xlWhole)
  63.                     If Not Rng(0) Is Nothing Then
  64.                         .Replace Rng(25), "=xxx", xlWhole               '¦p¦P¤u§@ªí´M§ä:¥þ³¡¨ú¥N ¬°¿ù»~ªº¤½¦¡
  65.                         .SpecialCells(xlCellTypeFormulas).Select
  66.                         S = Application.CountA(Selection) / P
  67.                        If S <= 1 Then
  68.                             S = Application.Match(S, [AA2:AG2], -1)     'Match ªº±Æ§Ç:¤j¨ì¤p
  69.                         Else
  70.                             S = 1
  71.                        End If
  72.                         Selection.Value = Rng(25)                       '´_­ì ¨ú¥Nªº¦r¦ê
  73.                         Selection.Interior.ColorIndex = Sheet1.[AA2].Cells(1, S).Interior.ColorIndex
  74.                     End If
  75.                 Set Rng(25) = Rng(25).Offset(1)                         '´M§ä¤U¤@­Ó¦r¦ê
  76.                 Loop
  77.             End With
  78.         Next
  79.         .Columns(Columns.Count - 1) = ""                '²M°£ ³Ì«á²Ä2Äæ¸ê®Æ
  80.         .Columns(Columns.Count) = ""                    '²M°£ ³Ì«á1Äæ¸ê®Æ
  81.         Application.ScreenUpdating = True
  82.         .CheckBoxes(Application.Caller).TopLeftCell.Select
  83.       End With
  84. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-12-17 16:45 ½s¿è

¦^´_ 10# cmo140497
§Aªº¸ê®ÆÅã¥Ü¬O2003ª© ¦ó¤£¦b2003¸Õ¬Ý
´ú¸Õ12# 2010ª© »Ý¬O
  1. .Columns(Columns.Count).AdvancedFilter xlFilterCopy, , .Cells(1, Columns.Count - 1), Unique:=True
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-12-20 09:44 ½s¿è

16# Àɮתºµ{¦¡½X,¸Õ¬Ý¬Ýµ{¦¡³B¸Ìªº³t«×¬O§_º¡·N!!
  1. Option Explicit
  2. Const xRow As Integer = 24
  3. Const xCol As Integer = 24
  4. Private Sub AUTO_OPEN()
  5.     Dim Rng As Range, E As Range, xi As Integer
  6.     Sheets("Overlap").Activate
  7.     Set Rng = [A:A]
  8.     Rng.Replace "ID", "=XXX", xlWhole
  9.     Set Rng = Rng.SpecialCells(xlCellTypeFormulas, xlErrors)
  10.     ActiveSheet.CheckBoxes.Delete
  11.     For Each E In Rng.Cells
  12.         With Cells(xi + 5, "AA")
  13.             With ActiveSheet.CheckBoxes.Add(.Left, .Top, .Width, .Height)
  14.                 .Caption = "Item" & xi + 1
  15.                 .OnAction = "Ex_Action"
  16.                 E.Offset(1, 1).Resize(xRow, xCol).Name = "_" & .Caption  '³]¸m½d³ò¦WºÙ
  17.             End With
  18.         End With
  19.         xi = xi + 1
  20.     Next
  21.     Rng.Value = "ID"
  22. End Sub
  23. Private Sub Ex_Action()
  24.     Dim cBox As Object, Rng As Range, r As Integer, y As Integer, xi As Integer
  25.     Dim Ar(), E As Variant, t As Date
  26.     t = Time
  27.     For Each cBox In ActiveSheet.CheckBoxes
  28.         If cBox.Value = 1 Then
  29.             If Rng Is Nothing Then Set Rng = Range("_" & cBox.Caption)
  30.             If Not Rng Is Nothing Then Set Rng = Union(Rng, Range("_" & cBox.Caption))
  31.         End If
  32.     Next
  33.     With Range("AI5").Resize(xRow, xCol)
  34.         .Interior.ColorIndex = xlNone
  35.         For Each cBox In .Cells
  36.             If cBox <> "___" Then cBox = 0
  37.         Next
  38.     End With
  39.     Application.ScreenUpdating = False
  40.     Range("B:Z").Interior.ColorIndex = xlNone
  41.     If Rng Is Nothing Then Exit Sub
  42.     ReDim Ar(1 To xRow, 1 To xCol)                                      '³]©w:°}¦C¤j¤p
  43.     '********  ¨C¤@­Ó½d³ò¤¤¦P¤@¦ì¸m¦³¸ê®Æªº:­p¼Æ
  44.     For Each cBox In Rng.Areas                                          '³B¸Ì¨C¤@­Ó½d³ò
  45.         For r = 1 To xRow
  46.             For y = 1 To xCol
  47.                 If cBox(r, y) = "___" Then GoTo 0                       '¤£³B¸Ì
  48.                 If cBox(r, y) <> 0 Then Ar(r, y) = Ar(r, y) + 1         '¬ö¿ý¸ê®Æ
  49. 0:
  50.             Next
  51.         Next
  52.     Next
  53.     '********  ¨C¤@­Ó½d³ò¤¤¦P¤@¦ì¸m¸ê®Æªº­p¼Æ¦Ê¤À¤ñ:³]¤UÃC¦â
  54.     For Each cBox In Rng.Areas
  55.         For r = 1 To xRow
  56.             For y = 1 To xCol
  57.                 xi = 0                                                  '¦Ê¤À¤ñ:Âk¹s
  58.                 If cBox(r, y) = "___" Then GoTo 1
  59.                 For Each E In Array(0, 0.19, 0.39, 0.59, 0.79, 0.99, 1)
  60.                     xi = xi + 1
  61.                     If Ar(r, y) / Rng.Areas.Count <= E Then Exit For    '¨ú±o¦Ê¤À¤ñ
  62.                 Next
  63.                 If Ar(r, y) > 0 Then cBox(r, y).Interior.ColorIndex = [AA2].Cells(1, xi).Interior.ColorIndex
  64.                                                                         '[AA2].Cells(1, xi):ÃC¦âªº¦ì¸m
  65. 1:
  66.             Next
  67.         Next
  68.     Next
  69.     '********  ²Î­p½d³ò¦ì¸m¸ê®Æ: ­p¼Æ, ¦Ê¤À¤ñÃC¦â
  70.     With Range("AI5")
  71.         For r = 1 To xRow
  72.             For y = 1 To xCol
  73.                 If .Cells(r, y) <> "___" Then
  74.                     .Cells(r, y) = IIf(Ar(r, y) = "", 0, Ar(r, y))
  75.                     If Ar(r, y) > 0 Then
  76.                     .Cells(r, y).Interior.ColorIndex = Rng(r, y).Interior.ColorIndex
  77.                     Else
  78.                     .Cells(r, y).Interior.ColorIndex = [AA2].Interior.ColorIndex
  79.                     End If
  80.                 End If
  81.             Next
  82.         Next
  83.     End With
  84.     Application.ScreenUpdating = True
  85.     MsgBox Format(t, "¶}©l hh:mm:ss") & vbLf & Format(Time, "µ²§ô hh:mm:ss") & vbLf & vbLf & Format(Time - t, "¶O®É hh:mm:ss")
  86. End Sub
½Æ»s¥N½X
¦^´_ 19# cmo140497

TOP

        ÀR«ä¦Û¦b : ¹ï¤÷¥À­nª¾®¦¡A·P®¦¡B³ø®¦¡C
ªð¦^¦Cªí ¤W¤@¥DÃD