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

[µo°Ý] replace missing value (¨D±Ï)

¦^´_ 20# jj369963
©Ò¥H¨Ã¤£»Ý­n*5/3¶Ü?
  1. Sub Replace_Blank()
  2. Dim A As Range, Ar(), B As Range
  3. Set Upw = CreateObject("Scripting.Dictionary") '±b±K
  4. Set dic = CreateObject("Scripting.Dictionary") '°Ñ·Ó
  5. fs = ThisWorkbook.Path & "\replace_rule.txt" 'TEXTÀɮצì¸m
  6. Close #1 '­Y¤w¸g¶}±Ò´N¥ýÃö³¬
  7. With Sheets("Sheet0")
  8. Open fs For Input As #1
  9. Do Until EOF(1)
  10.    Line Input #1, mystr
  11.    If InStr(mystr, ",") > 0 Then
  12.    s = InStr(mystr, "(")
  13.    n = InStr(s, mystr, ")")
  14.    mystr = Mid(mystr, s + 1, n - s - 1)
  15.    For Each C In Split(mystr, ",")
  16.      Set A = .Rows(1).Find(C)
  17.      ReDim Preserve Ar(i)
  18.      Ar(i) = Split(A.Address, "$")(1)
  19.      i = i + 1
  20.    Next
  21.    For Each p In Ar
  22.       dic(p) = Ar '°O¿ý¤½¦¡°Ñ·ÓÄæ¦ì
  23.    Next
  24.    Erase Ar: i = 0
  25.    End If
  26. Loop
  27. Close #1
  28. With Sheets("Sheet1")
  29.   For Each A In .Range(.[A2], .[A2].End(xlDown))
  30.      Upw(CStr(A)) = Array(A.Offset(, 3).Value, A.Offset(, 2).Value) '°O¿ý±b±K
  31.   Next
  32. End With
  33. '¨ú¥N½Æ¿ï¦ì¸m
  34. Set A = .Range(.[H2], .Cells(.Rows.Count, "CQ").End(xlUp)).Find("*,*")
  35. If Not A Is Nothing Then
  36. Do
  37. ay = Split(A, ",")
  38. For i = 0 To UBound(ay)
  39. ReDim Preserve Ar(i)
  40. Ar(i) = Val(ay(i))
  41. Next
  42.   A.Value = Round(Application.Average(Ar), 0)
  43.   Erase Ar
  44.   Set A = .Range(.[H2], .Cells(.Rows.Count, "CQ").End(xlUp)).Find("*,*", A)
  45. Loop Until A Is Nothing
  46. End If
  47. i = 0
  48. .Select
  49. For Each A In .Range(.[F2], .Cells(.Rows.Count, "F").End(xlUp))
  50.    A.Offset(, -5).Resize(, 2) = Upw(CStr(A)) '¶ñ¼g±b±K
  51.    r = A.Row
  52.    For Each B In .Range(.Cells(r, "H"), .Cells(r, "CQ"))
  53.       If B = "" Then  '§ä¨ìªÅ®æ
  54.       ay = dic(Split(B.Address, "$")(1))
  55.       If Not IsEmpty(ay) Then '¸ÓÀx¦s®æ¦³³Q¤½¦¡¤Þ¥Î
  56.          For i = 0 To UBound(ay)
  57.          If .Range(ay(i) & r) <> "" Then '¤Þ¥Îªº°Ñ·Ó«DªÅ¥Õ¤~­p¤J°}¦C
  58.            ReDim Preserve Ar(j)
  59.            Ar(j) = ay(i) & r
  60.            j = j + 1
  61.          End If
  62.          Next
  63.         If j > 0 Then B.Value = Round(Application.Evaluate("Average(" & Join(Ar, ",") & ")"), 0)
  64.          Erase Ar
  65.          j = 0
  66.       End If
  67.       End If
  68.     Next
  69. Next
  70. End With
  71. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 21# Hsieh

Dear Hsiehª©¤j¡G

             ¯u¬O·PÁ¦A·PÁ¡AÂZ±z¶O¤ß¤F(¯u¬O¶O«Ü¦h¤ß)¡CµÛ¹êı±o·P°Ê·Q¦b¤ß¤¤©I³Û
            works successfully
           ¦pªG¤£¤¶·N·Q¦A½Ð±Ð¤@­Ó°ÝÃD¡A¹ï¤£°_¤Sµ¹±z¥XÃD¤F
          ¦pªG·Q¦b¶]§¹¤§«á¡A¥hÀˬd ¨C¤@¦C¤¤ÁÙ¦³ªÅ¥Õªº(´N¬O¨S¦³³Qµ{¦¡¨ú¥N)¡A¦]¬°¾ã¤jÃD¨S¼g¡A¯Ê¥¢­È¹L¦h¡A¹³³o¼Ëªº¸ê®Æ¨º¤@¦C¡A¥H¤U¨ÌÃø©ö«×¡A¿ï¾Ü¨ä¤@³B²z¡G
           1.¦C¦³ªÅ¥Õ­È¡A¾Ç¸¹¼Ð°OÃC¦â
           2.¦C¦³ªÅ¥Õ­È¡A±N¸Ó¦C±Æ§Ç©ó³Ì«á(´N¬O­n½Æ»s¸Ó¦C¡A¶K©ó³Ì«á¡A¤S§R°£­ì¥»ªº¦C)
           3.¦C¦³ªÅ¥Õ­È¡A±N¸Ó¦C°Å¤U¡A¶K¦Ü¨ä¥Lsheet
         
            ¯u¬O¤j¤j¤£¦n·N«ä¡A¦A½Ð«ü±Ð
          ·PÁÂ

TOP

¦^´_ 21# Hsieh

Dear Hsiehª©¤j¡G

   ·PÁ±z¶O¤ßªº«ü¾É¡A¨ú¥N®É¤£»Ý­n*5/3

but ¬Q¤Ñ¥b©]µo²{¨ì¤@­Ó°ÝÃD¡A¦³¤Ï¦VÃD¡A§Úªº¤Ñ
©Ò¥H¤S¨Ó½Ð¯q
´N¬O¦b ²Ä1ÃD¨ì²Ä48ÃD
­ì¥»µª®×¬O  1 convert to 3  (1§ï3)
                         2 convert to 1  (2§ï1)
                         3 convert to  2 (3§ï2)
                           ½Æ¿ï´N²MªÅ
    ¤§«á¨Ì³W«h¨ú¥NªÅ­È

¯u¬Osorry¨S¦³ª`·N¨ì¡A¦A·Ð½Ð«ü±Ð
ÁÂÁÂ

TOP

¥»©«³Ì«á¥Ñ jj369963 ©ó 2013-10-10 16:50 ½s¿è

¦^´_ 21# Hsieh

Dear Hsiehª©¤j¡G

  ¯u¬Osorry¡A§Úªº¸£³U¤w¸g²V¶Ã¤F¡CÁÙ³y¦¨³Â·Ð¯u¬O©êºp¡A­«·s«ä¦Ò¾ã­ÓÅ޿趶§Ç¡A À³¸Ó¬O³o¼Ë¡G

1.²MªÅ½Æ¿ï
2. ¦b ²Ä1ÃD¨ì²Ä48ÃD
     ­ì¥»µª®×¬O  1 convert to 3  (1§ï3)
                             2 convert to 1  (2§ï1)
                             3 convert to  2 (3§ï2)
3.¦A¨Ì³W«h¨ú¥N¡A¤£»Ý­n*5/3¡Aµ{¦¡½X°õ¦æ¤£»Ý­n¦³CR:DCÄæ¦ìªº¤½¦¡
4.¼Ð°O ¤@¤jÃD¨S¼gªº(ÁÙ¦³ªÅ­È)ªº ¾Ç¸¹  

¯u¬O©êºp¤@ª½¥´ÂZ¡A¦A³Â·Ð±z«ü±Ð
ÁÂÁÂ

TOP

¦^´_ 21# Hsieh


    Dear Hsiehª©¤j¡G

      ¤S¨Ó°Q±Ð¡A ¯u¤£¦n·N«ä¡A¥Ø«e°w¹ï ²Ä1ÃD¨ì²Ä48ÃD ªº Âà´«
­ì¥»µª®×¬O  1 convert to 3  (1§ï3)
                         2 convert to 1  (2§ï1)
                         3 convert to  2 (3§ï2)

  ·Q¨ìªº¬O =IF(H2=1,3,IF(H2=2,1,IF(H2=3,2,""))) ©¹¥k©¹¤U¡A¦ý¬O¥Î¤½¦¡µLªk¨ú¥N­ì¥»cell ¡A¤£ª¾¬O§_¥i¥H¥Îvba?

©Î¬O¥H¤U»yªk(¤£ª¾¹Dvba¾A¥Î¤U¦C»yªk¶Ü)

RECODE
  ²Ä1ÃD ²Ä2ÃD ²Ä3ÃD ²Ä4ÃD ²Ä5ÃD ²Ä6ÃD ²Ä7ÃD ²Ä8ÃD ²Ä9ÃD ²Ä10ÃD ²Ä11ÃD ²Ä12ÃD ²Ä13ÃD ²Ä14ÃD ²Ä15ÃD ²Ä16ÃD ²Ä17ÃD ²Ä18ÃD ²Ä19ÃD
  ²Ä20ÃD ²Ä21ÃD ²Ä22ÃD ²Ä23ÃD ²Ä24ÃD ²Ä25ÃD ²Ä26ÃD ²Ä27ÃD ²Ä28ÃD ²Ä29ÃD ²Ä30ÃD ²Ä31ÃD ²Ä32ÃD ²Ä33ÃD ²Ä34ÃD ²Ä35ÃD ²Ä36ÃD
  ²Ä37ÃD ²Ä38ÃD ²Ä39ÃD ²Ä40ÃD ²Ä41ÃD ²Ä42ÃD ²Ä43ÃD ²Ä44ÃD ²Ä45ÃD ²Ä46ÃD ²Ä47ÃD ²Ä48ÃD  (1=3)  (2=1)  (3=2)  .
EXECUTE .

¦A·Ð½Ð«ü±Ð Åܼƪ½±µ¦bcellÂà´«ªº¤èªk

ÁÂÁÂ &µL­­·P¿E

TOP

¦^´_ 25# jj369963
  1. With [H:BC] '1~48ÃDªºÄæ¦ì
  2. .Replace 1, "3@", xlWhole '±N1¥Î¤@­Ó¤£±`¥Î²Å¸¹¨ú¥N
  3. .Replace 2, 1, xlWhole '±N2¥Î1¨ú¥N
  4. .Replace 3, 2, xlWhole '±N3¥Î2¨ú¥N
  5. .Replace "3@", 3, xlWhole '±N¤£±`¥Î²Å¸¹¥Î3¨ú¥N
  6. End With
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 26# Hsieh


    Dear Hsiehª©¤j¡G

   ÁÂÁ±z¼ö¤ßªº¦^ÂСA«D±`·P¿E¡A­ì¨Ó§Þ¥©¬O¡y¥Î¤@­Ó¤£±`¥Î²Å¸¹¨ú¥N¡z¡A¯u¬O§®¡A·PÁ¡C
   ¥t¥~·Q¦A½Ð±Ð¤@­Ó°ÝÃD(§Ú«ç»ò¦³µL¼Æªº°ÝÃD§r¡A¤Ñ§r)
    ¤§«e¬Ý¤å³¹ §Úª¾¹Dvba¥i¥H·j´MÃöÁä¦r¡A¨ÃÃC¦â¼Ð°O¾ã¦C
   §Úªº·N«ä¬O
   ¾ã­Ó¸ê®Æ¥þ³¡³B²z§¹«á¡AÁÙ¬O¦³missing(¦]¬°µL¤½¦¡¥i¥H¹ïÀ³¨ú¥N)¡A©Ò¥H¬O§_¥i¥H
   ¦bA-CQÄæ ·j´Mmissing ¡A¨Ã±N¾ã¦C¼Ð°OÃC¦â(¶À¦â)¡AÁ|¨Ò¦pªGA15¬°ªÅ­È¡A´N±N²Ä15¦C¥þ³¡¼ÐÃC¦â¡A¨Ì¦¹Ãþ±À
   
   ¥ç©Î¬O±NÁÙ¦³ªÅ­Èªº¾ã¦C ²¾¨ì§Oªºsheet,¦psheet2 ->³o¼Ëªº¤è¦¡¤£ª¾¬O§_¥i¥H¥Îvba??

    ¦A·Ð½Ð¤j¤j¡A¦h¦h«ü±Ð
   ¦A¦¸·PÁÂ

TOP

¦^´_ 27# jj369963
¾ã­Ó¸ê®Æ¥þ³¡³B²z§¹«á¡AÁÙ¬O¦³missing(¦]¬°µL¤½¦¡¥i¥H¹ïÀ³¨ú¥N)¡A©Ò¥H¬O§_¥i¥H
   ¦bA-CQÄæ ·j´Mmissing ¡A¨Ã±N¾ã¦C¼Ð°OÃC¦â(¶À¦â)¡AÁ|¨Ò¦pªGA15¬°ªÅ­È¡A´N±N²Ä15¦C¥þ³¡¼ÐÃC¦â¡A¨Ì¦¹Ãþ±À

¼ÐÃC¦â¥Î®æ¦¡¤Æ±ø¥ó§Y¥i¹F¦¨
=(COUNTBLANK($A1:$CQ1)>0)*(COUNTA($A1:$CQ1)>0)
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2013-11-16 22:48 ½s¿è

¦^´_ 28# Hsieh


   Dear Hsieh¤j¤j¡G
                                    «D±`·PÁ±zªº¦^ÂСA­ì¨Ó¥ÎÂIÅÞ¿è¡A¨ÃÂǥѮ榡¹º³]©w§Y¥i°µ¨ì¡A·P¿E¡C
                                     ²Ä¤@¦¸¾Ç²ßVBA¡AÁÙ·d¤£²Mª¬ªpªº»¡¡A¯uªº«Ü·PÁ±zªº«ü¾É¡C§Úµy·L­×§ï¤@¤U¦p¤U»yªk¡G
                                ¦ý¬O§Ú·Q¦A½Ð°Ý¤@­Ó°ÝÃD¡A¦]¬°§Úªº­ì©lÀɮ׬O ¦r¦ê ¡A§Ú·Q§ï¦¨¼Æ­È  ±qDÄæ¨ìCOÄæ¡A§Úª¾¹D¥i¥H§ï Àx¦s®æ®æ¦¡¡A©Î¤â°Ê«ö¶sÂà¼Æ­È¡A
                               ¦ýÁÙ¬O§Ô¤£¦í·Q½Ð±Ð¤@¤U¦p¦ó¥i¥H¥Îvba§â¤å¦rÂন¼Æ­È¡A¦pªþÀÉ¡A¦A½Ð¦h«ü±Ð¡A
                              ¥t¥~¯u±o«Ü·PÁ±zÅý§Úª¾¹DVBA±o¦nª±¦³½ì¡C
  1. Sub Replace_Blank()
  2. Columns("A:A").Select
  3.     Selection.Insert Shift:=xlToRight
  4.     Selection.Insert Shift:=xlToRight


  5. Range("A1").Select
  6.     ActiveCell.FormulaR1C1 = "user"
  7.     Range("B1").Select
  8.     ActiveCell.FormulaR1C1 = "password"


  9.     Dim E As Range
  10.     For Each E In Range("f:f").SpecialCells(xlCellTypeConstants)
  11.         E.Value = "'" & Replace(E, ",", "")
  12.     Next


  13. With [H:BC]
  14. .Replace "*,*", "", xlWhole '²M°£½Æ¿ï
  15. End With
  16. With [H:BC] '1~48ÃDªºÄæ¦ì


  17. .Replace 1, "3@", xlWhole '±N1¥Î¤@­Ó¤£±`¥Î²Å¸¹¨ú¥N


  18. .Replace 2, 1, xlWhole '±N2¥Î1¨ú¥N


  19. .Replace 3, 2, xlWhole '±N3¥Î2¨ú¥N


  20. .Replace "3@", 3, xlWhole '±N¤£±`¥Î²Å¸¹¥Î3¨ú¥N


  21. End With
  22. Dim A As Range, Ar(), B As Range
  23. Set Upw = CreateObject("Scripting.Dictionary") '±b±K
  24. Set dic = CreateObject("Scripting.Dictionary") '°Ñ·Ó
  25. fs = ThisWorkbook.Path & "\replace_rule.txt" 'TEXTÀɮצì¸m
  26. Close #1 '­Y¤w¸g¶}±Ò´N¥ýÃö³¬
  27. With Sheets("Sheet0")
  28. Open fs For Input As #1
  29. Do Until EOF(1)
  30.    Line Input #1, mystr
  31.    If InStr(mystr, ",") > 0 Then
  32.    s = InStr(mystr, "(")
  33.    n = InStr(s, mystr, ")")
  34.    mystr = Mid(mystr, s + 1, n - s - 1)
  35.    For Each C In Split(mystr, ",")
  36.      Set A = .Rows(1).Find(C)
  37.      ReDim Preserve Ar(i)
  38.      Ar(i) = Split(A.Address, "$")(1)
  39.      i = i + 1
  40.    Next
  41.    For Each p In Ar
  42.       dic(p) = Ar '°O¿ý¤½¦¡°Ñ·ÓÄæ¦ì
  43.    Next
  44.    Erase Ar: i = 0
  45.    End If
  46. Loop
  47. Close #1
  48. With Sheets("Sheet1")
  49.   For Each A In .Range(.[A2], .[A2].End(xlDown))
  50.      Upw(CStr(A)) = Array(A.Offset(, 3).Value, A.Offset(, 2).Value) '°O¿ý±b±K
  51.   Next
  52. End With
  53. '¨ú¥N½Æ¿ï¦ì¸m
  54. Set A = .Range(.[H2], .Cells(.Rows.Count, "CQ").End(xlUp)).Find("*,*")
  55. If Not A Is Nothing Then
  56. Do
  57. ay = Split(A, ",")
  58. For i = 0 To UBound(ay)
  59. ReDim Preserve Ar(i)
  60. Ar(i) = Val(ay(i))
  61. Next
  62.   A.Value = Round(Application.Average(Ar), 0)
  63.   Erase Ar
  64.   Set A = .Range(.[H2], .Cells(.Rows.Count, "CQ").End(xlUp)).Find("*,*", A)
  65. Loop Until A Is Nothing
  66. End If
  67. i = 0
  68. .Select
  69. For Each A In .Range(.[F2], .Cells(.Rows.Count, "F").End(xlUp))
  70.    A.Offset(, -5).Resize(, 2) = Upw(CStr(A)) '¶ñ¼g±b±K
  71.    r = A.Row
  72.    For Each B In .Range(.Cells(r, "H"), .Cells(r, "CQ"))
  73.       If B = "" Then  '§ä¨ìªÅ®æ
  74.       ay = dic(Split(B.Address, "$")(1))
  75.       If Not IsEmpty(ay) Then '¸ÓÀx¦s®æ¦³³Q¤½¦¡¤Þ¥Î
  76.          For i = 0 To UBound(ay)
  77.          If .Range(ay(i) & r) <> "" Then '¤Þ¥Îªº°Ñ·Ó«DªÅ¥Õ¤~­p¤J°}¦C
  78.            ReDim Preserve Ar(j)
  79.            Ar(j) = ay(i) & r
  80.            j = j + 1
  81.          End If
  82.          Next
  83.         If j > 0 Then B.Value = Round(Application.Evaluate("Average(" & Join(Ar, ",") & ")"), 0)
  84.          Erase Ar
  85.          j = 0
  86.       End If
  87.       End If
  88.     Next
  89. Next
  90. End With

  91. Cells.Select
  92.     Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
  93.         "=(COUNTBLANK($A1:$CQ1)>0)*(COUNTA($A1:$CQ1)>0)"
  94.     Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
  95.     With Selection.FormatConditions(1).Interior
  96.         .PatternColorIndex = xlAutomatic
  97.         .ThemeColor = xlThemeColorAccent6
  98.         .TintAndShade = 0.399945066682943
  99.     End With
  100.     Selection.FormatConditions(1).StopIfTrue = True


  101. End Sub


½Æ»s¥N½X
[attach]16355[/attach]

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2013-11-15 08:12 ½s¿è

¦^´_ 21# Hsieh


    DEAR Hsieh ª©¤j¡G

          SORRY¡A¤S¨Ó¥´ÂZ¡A®M¥Î¤½¦¡«á¡A·|µo²{¨ä¤¤

            ¦n©_Äw¹º = MEAN(²Ä52ÃD,²Ä60ÃD,²Ä64ÃD)
             §Æ±æ¥ß©R = MEAN(²Ä57ÃD,²Ä65ÃD,²Ä68ÃD)
              ¦w¦b³B¹Ò = MEAN(²Ä56ÃD,²Ä66ÃD,²Ä73ÃD)
               ¦³®É¨Ã¨S¦³¨Ì·Ó¤½¦¡¥|±Ë¤­¤J
¦pÀÉ®×(²Ä¤G¦C)
²Ä57ÃD=MISSING
²Ä65ÃD=4
²Ä68ÃD)=5
©Ò¥H²Ä57ÃD=(4+5)/2=4.5=5  ¦ý¥X¨Óªºµ²ªG¬O ²Ä57ÃD=4

¦P²z(²Ä¤G¦C)
²Ä52ÃD=5
²Ä60ÃD=MISSING
²Ä64ÃD=4

©Ò¥H²Ä60ÃD=(4+5)/2=4.5=5  ¦ý¥X¨Óªºµ²ªG¬O ²Ä60ÃD=4

¦ý»yªk¤w¦³ROUND
If j > 0 Then B.Value = Round(Application.Evaluate("Average(" & Join(Ar, ",") & ")"), 0)

¦]¬°§ä¤£¨ìround¿ù»~ªº­ì¦]¡A©Ò¥H¤S¨Ó½Ð¯q¡A

¦A·Ð½Ð¦h«ü±Ð¡AÁÂÁ¡C

[attach]16459[/attach]

TOP

        ÀR«ä¦Û¦b : ·R¤£¬O­n¨D¹ï¤è¡A¦Ó¬O­n¥Ñ¦Û¨­ªº¥I¥X¡C
ªð¦^¦Cªí ¤W¤@¥DÃD