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

[µo°Ý] ½Ð°Ý¦p¦ó¥Îexcel VBA¼g¤@­Ó¥H¥ý¶i¥ý¥Xªº¤è¦¡¨Ó¨ú±o²£«~ªº¼Æ¶q»P¥­§¡»ù®æ

[µo°Ý] ½Ð°Ý¦p¦ó¥Îexcel VBA¼g¤@­Ó¥H¥ý¶i¥ý¥Xªº¤è¦¡¨Ó¨ú±o²£«~ªº¼Æ¶q»P¥­§¡»ù®æ

­Ó°Ý¤j¤j¦pÃD
½Ð°Ý¦p¦ó¥Îexcel VBA¼g¤@­Ó¥H¥ý¶i¥ý¥Xªº¤è¦¡¨Ó¨ú±o²£«~ªº¼Æ¶q»P¥­§¡»ù®æ
¦³¥H¤Uªº¸ê®Æ,¦ý¤p§Ì¹ê¦b·Q¤£¥X¸Ó¦p¦ó¼g¥X¨Ó,¶R¶i½æ¥X¶·¥H¤é´Á¬°¥D
­n¨ú±o¥Ø«e²£«~ªº³Ñ¾l¼Æ¶q»P³Ñ¾l¼Æ¶qªº¦¨¥»§¡»ù,²£«~©ú²Ó¦pªþ¥ó

ÁʶR¤é´Á,²£«~½s¸¹,ÁʶR»ù®æ,¶i³f¼Æ¶q,¥X³f¼Æ¶q
20120102,1166,27,0,2000
20120102,116P,27.2,0,2000
20120102,5511,27.2,0,1000
20120102,5515,27.1,0,1000
20120102,585J,27,5000,0
20120102,585J,27.05,1000,0
20120102,592a,27.1,1000,0
20120102,5962,27.2,0,2000
20120102,616K,27.25,0,1000
20120102,7001,27,0,2000
20120102,7001,27.05,0,1000
20120102,7001,27.1,0,1000
20120102,700K,27.3,1000,0
20120102,779z,27.7,0,1000
20120102,8560,27.05,1000,0
20120102,8560,27.1,2000,0
20120102,8560,27.25,1000,0
20120102,8560,27.7,0,3000
20120102,8843,27,0,1000
20120102,9108,27.25,1000,0
20120102,9108,27.7,0,1000
20120102,913R,27.7,5000,0
20120102,9187,27.05,0,1000
20120102,9313,27.3,0,1000
20120102,9363,27,0,1000
20120102,9801,27.2,10000,0
20120102,9817,27.1,0,1000
20120102,983Z,27.2,0,3000
20120102,984C,27.25,0,1000
20120102,984K,27,2000,0
20120102,9887,27,0,1000
20120102,9887,27.2,0,2000
20120103,1035,27.05,2000,0
20120103,1160,27.45,5000,0
20120103,1166,27.05,0,1000
20120103,116L,27.05,0,1000
20120103,116L,27.45,0,1000
20120103,538N,27.45,0,2000
20120103,572D,27.5,0,5000
20120103,5926,27.05,4000,0
20120103,592M,27.5,0,2000
20120103,7003,27.45,2000,0
20120103,7003,27.5,10000,0
20120103,700K,27.45,0,1000
20120103,700W,27.05,1000,0
20120103,700j,27.05,4000,0
20120103,8560,27.05,2000,0
20120103,8560,27.45,0,1000
20120103,8560,27.5,0,2000
20120103,8850,27.45,0,1000
20120103,9183,27.45,1000,0
20120103,9185,27.05,1000,0
20120103,918D,27.05,0,10000
20120103,921Y,27.05,0,1000
20120103,9303,27.05,1000,0
20120103,9303,27.5,0,1000
20120103,9649,27.05,0,1000
20120103,979H,27.05,0,1000
20120103,9817,27.45,0,2000
20120104,1035,26.8,0,3000
20120104,1112,27,0,1000
20120104,1162,27.3,1000,0
20120104,116G,26.85,0,1000
20120104,5182,27,0,1000
20120104,551X,27,0,1000
20120104,585V,26.8,0,6000
20120104,700K,27.15,1000,0
20120104,700j,26.8,6000,0
20120104,700j,27,1000,0
20120104,8560,26.8,0,1000
20120104,8560,27,1000,0
20120104,8560,27.15,0,1000
20120104,8560,27.3,0,1000
20120104,884A,26.8,0,3000
20120104,9108,27,1000,0
20120104,9135,27.15,0,2000
20120104,9183,27.15,0,1000
20120104,9274,26.85,1000,0
20120104,9647,27,1000,0
20120104,9801,26.8,8000,0
20120104,981a,26.8,0,5000
20120104,982A,26.8,1000,0
20120104,9887,27,0,2000
20120104,9891,27,1000,0
20120104,989V,26.8,3000,0
20120104,989V,27.15,2000,0
20120104,989Z,27.15,1000,0

test.rar (612 Bytes)

²£«~¶R½æ¸ê®Æ©ú²Ó

¦^´_ 22# white5168
§â¾ãÅé¬yµ{·§©Àµù¸Ñ«á¡A¬Ý¬Ý»P§Aªº·Qªk¸¨®t¦b­þ?
  1. Sub Get_Data()
  2. Dim Ar(), Ay(), x, Mystr$, A
  3. Set d = CreateObject("Scripting.Dictionary")
  4. Set d1 = CreateObject("Scripting.Dictionary")
  5. Set d2 = CreateObject("Scripting.Dictionary")
  6. ChDir ThisWorkbook.Path
  7. fs = Application.GetOpenFilename("³rÂI¤À¹j (CSV) (*.csv), *.csv") '¶}±Ò¸ê®ÆÀÉ®×¹ï¸Ü¤è¶ô¿ï¾ÜCSVÀÉ®×

  8. Open fs For Input As #1 'Ū¨úCSVÀÉ®×
  9. Do Until EOF(1)
  10.    Line Input #1, Mystr 'Ū¨ú¤@¦æ¸ê®Æ¼g¤JÅܼÆ
  11.    A = Split(Mystr, ",") '±N¸ê®Æ¤Á³Î¦s¤J°}¦C
  12.    If Val(A(0)) > 0 And Val(A(0)) <= [B1] Then '§PÂ_¬O§_¦bµ²ºâ¤é´Á¤§«eªº¸ê®Æ
  13.    If IsEmpty(d(A(1))) Then '¥H²£«~½s¸¹¬°¯Á¤Þ­Y¤£¦s¦b
  14.        For i = 1 To Val(A(3)) '¥H¶R¤J¼Æ¶q°µ°j°é¡B°O¾Ð¦í¨C¤@­Óªº³æ»ù
  15.           ReDim Preserve Ar(i)
  16.           Ar(i - 1) = Val(A(2))
  17.        Next
  18.        If Val(A(3)) > 0 Then d(A(1)) = Ar '¦pªG¦³¼Æ¶q´N±N°}¦C¦s¨ì¦r¨å¤¤
  19.        Else '¤]´N¬O¦³²Ä¤Gµ§¥H¤W¶R¤J®É°õ¦æ
  20.        Ar = d(A(1)) '¥ý¨ú¥X¸Ó½s¸¹¤w¸gÁʶRªº¸ê®Æ¦s¤J°}¦C
  21.        s = UBound(Ar)
  22.          For i = 1 To Val(A(3)) '±N¨Cµ§¸ê®Æ³æ»ù¥[¤J¦¹°}¦C
  23.            ReDim Preserve Ar(s + i)
  24.            Ar(s + i - 1) = Val(A(2))
  25.          Next
  26.        s = UBound(Ar)
  27.          d(A(1)) = Ar '±N°}¦C¦^¦s¨ì¦r¨åª«¥ó
  28.     End If
  29.     If Val(A(4)) > 0 Then '½æ¥X¸ê°T³B²z¡A»P¶R¤JÆ[©À¬Û¦P
  30.        If IsEmpty(d1(A(1))) Then
  31.        For i = 1 To Val(A(4))
  32.           ReDim Preserve Ar(i)
  33.           Ar(i - 1) = Val(A(2))
  34.        Next
  35.        If Val(A(4)) > 0 Then d1(A(1)) = Ar
  36.        Else
  37.        Ar = d1(A(1))
  38.        s = UBound(Ar)
  39.          For i = 1 To Val(A(4))
  40.            ReDim Preserve Ar(s + i)
  41.            Ar(s + i - 1) = Val(A(2))
  42.          Next
  43.          d1(A(1)) = Ar
  44.     End If
  45.     End If
  46.     End If
  47.    Erase Ay: Erase Ar '³B²z¤U¤@µ§¸ê®Æ«e¥ý§â­ì¨Óªº¶R½æ°O¾Ð®ø°£
  48. Loop
  49. Close #1 'Ãö³¬CSVÀÉ®×
  50. For Each ky In d1.keys
  51.    If IsArray(d1(ky)) Then Ar = d1(ky): x = UBound(Ar) Else x = 0 '¥X³f¸ê®Æ­Y¬O°}¦C´N¨ú¥X°}¦C¥i±oª¾¨ì©³¦³´Xµ§¥X³f¸ê°T
  52.    If IsArray(d(ky)) Then Ay = d(ky): y = UBound(Ay) Else y = 0 '¶i³f¸ê®Æ­Y¬O°}¦C´N¨ú¥X°}¦C¥i±oª¾¨ì©³¦³´Xµ§¶i³f¸ê°T
  53.    '¥H¤U´N¤£¦Pª¬ªp­pºâ¦UÄæ¦ìÀ³¦³ªº­È¼g¤J°}¦C
  54.    If x = 0 And y > 0 Then '¥u¶i¤£¥X
  55.         bp = Application.Average(Ay) '¶i³f¥­§¡»ù
  56.       d2(ky) = Array(ky, y, 0, 0, Abs(y - x), y - x, Round(bp, 2), 0)
  57.       bp = 0
  58.       ElseIf y = 0 And x > 0 Then '¥u¥X¤£¶i
  59.       sp = Application.Average(Ar) '¥X³f¥­§¡»ù
  60.       d2(ky) = Array(ky, y, x, 0, 0, y - x, 0, Round(sp, 2))
  61.       sp = 0
  62.       ElseIf x > 0 And y > 0 Then
  63.          If x > y Then '¥X¤j©ó¶i
  64.          w = 0: w1 = y - x
  65.          For i = 0 To y - 1
  66.          pr = pr + Ar(i) - Ay(i) '­pºâ¥X³f»P¶i³fªº»ù®t²Ö­p¡B³o¬O¯u¥¿Àò§Q­È¥i¯à»P´£°ÝªÌªºÆ[©À®t²§
  67.          Next
  68.          For j = i To x - 1 '¤£°÷¦©­pºâ
  69.          nr = nr + Ar(i)
  70.          Next
  71.          nr = nr / (x - y) '¤£¨¬¶q
  72.          ElseIf x < y Then '¶i¤j©ó¥X
  73.          w1 = 0: w = y - x
  74.          For i = 0 To x - 1
  75.          pr = pr + Ar(i) - Ay(i) '­pºâ¥X³f»P¶i³fªº»ù®t²Ö­p¡B³o¬O¯u¥¿Àò§Q­È¥i¯à»P´£°ÝªÌªºÆ[©À®t²§
  76.          Next
  77.          For j = i To y - 1 '³Ñ¾l¶q­pºâ
  78.          sr = sr + Ay(i)
  79.          Next
  80.          sr = sr / Abs(x - y) '¤£¨¬¶q
  81.          End If
  82.          d2(ky) = Array(ky, y, x, pr, w, w1, Round(sr, 2), Round(nr, 2)) '¼g¤J°}¦C
  83.          pr = 0: nr = 0: sr = 0
  84.    End If
  85.    Erase Ay: Erase Ar
  86. Next
  87. [A4:H65536] = ""
  88. [A4].Resize(d2.Count, 8) = Application.Transpose(Application.Transpose(d2.items))
  89. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 25# white5168

¥ý«e¦b¥t¤@©«¸Ì(»P¥»©«¤º®e¬Û¦P,­«Âеo©«¤F)¤w§@¦^ÂÐ
Hsieh¶Wª©¦b¥»©«¸Ì¥ç§@¤F¦^ÂÐ

ªþ¤WHª©»PRª©µ{¦¡°õ¦æµ²ªG¤§¤ñ¸û¨Ñ°Ñ¦Ò,¦³¤£¹ïªº¦a¤è¦A§@¦^ÂÐ
¶À¦âºô©³§Y¬°2­Óª©¥»¤£¦P¤§³B

³Ì«á¸ê®Æ Rª©vsHª©.rar (8.32 KB)

TOP

¥»©«³Ì«á¥Ñ white5168 ©ó 2012-5-2 00:22 ½s¿è

bbojj¤j¤j
ªº½T¬O¨C¤é¦UªÑ¦b¥þ¥x©Ò¦³劵°Óªº¦¨¥æ©ú²Ó,§Ú¬O¥Îpython§ì¤U¨Ó(¥ÎExcel VBA§ì¸ê®Æ·|«ÜºC,¦Ó¥B·|·í,¦]¬°¨C¤Ñªº¸ê®Æ¶q´N¬ù70MB~90MB),¦p¦A¥[¤W­n¤ÀªR³o¨Ç¸ê®ÆÅK©w§óºG
¦]¦¹¥Hpython§ì¸ê®Æ(°ê¥~¤w¦³±Npython©w¦ì¬°ª÷¿Äªºµ{¦¡»y¨¥),MySQL©ÎAccess¦s¸ê®Æ,Excel VBA¨Ó§@¸ê®Æ¤ÀªR¤~·|¬O¤£¿ùªº¬[ºc¿ï¾Ü,¥u¥i±¤¥Ø«e³o¸Ì¨Ã¨S¦³¹J¨ì·|¨Ï¥Îpythonªº¤H,¦³¿³½ì¥i¥H¬Û¤¬°Q½×,¤]«ØijªO¥D¯à¶}¤@­Ópythonªº°Q½×ª©
Â÷ÃD¤F,¯u©êºp,§ÚÁÙ¬O¥ý¨Ä¨Ä¾Ç¦nExcel VBA

TOP

¥»©«³Ì«á¥Ñ wang ©ó 2012-5-2 21:20 ½s¿è

¹ï¤£°_  ·|¿ù·N  ¦Û§R

TOP

¥»©«³Ì«á¥Ñ white5168 ©ó 2012-5-1 17:58 ½s¿è

ÁÂÁÂHsieh¤j¤jªº¦^ÂÐ
§Ú·Q¥u¯à¥ý¸Õ¸Õ¬Ý±z©Ò¶Kªºµ{¦¡½X,¦Ü©óªþ¥óªº³¡¥÷µ¥¤É¯Å«á¦A¤U¸ü,¥ý¸Õ¸Õ¬Ý¬ÛÃöªº³¡¤À¬O§_¥i¦æ

¨ä¹ê­ì©l¸ê®Æ¤¤ÁÙ¦³¥]§t±q¤µ¦~¦~ªì¨ì²{¦bªº¥æ©ö¤é´Á,¼t°Ó,¦Ó¨C®a¼t°Óªº°Ó«~¤S¤£¬Û¦P, ¤S©È¤j®a¬Ý¤F·|§óÀY©ü,©Ò¥H§Ú¥Ø«e¥u¦C°Ó«~ªº¶R½æ©ú²Ó
µ¥§Ú¥ý¬Ý¤j¤j¼gªº§¹«á¦A¸ò±z½Ð¯q·í¥[¤J¼t°Ó«áªº¸ê°T,§Ú¥i¥H¥ý¹w§i¼t°Ó¦³1090¦h®a,¦Ó¨C®a½æªº°Ó«~¥[¥[´î´îªºÁ`¦@¦³1400¦h¼Ë,¦Ó³o¨âÃ䪺¸ê®Æ¶qÁÙ¦b¼W¥[·í¤¤,¬Û«H³o¼ËªºÃø«×¤S§ó°ª
§Æ±æ¯à±q¤j¤jªº¸gÅ礤§l¨ú³B²z³o¼ËÃe¤j¸ê®Æªº¤èªk

TOP

¦^´_ 20# white5168
§Ú¨Ã«D¬ì¯Z¥X¨­¡A¥uÀ´¤@ÂIVBA¥Ö¤ò¡A¨ä¥Lµ{¦¡¤£À´
¦Ü©ó±z©Ò¿×¼Ò²Õ¤Æ¡A§Ú¨Ã¤£¤F¸Ñ¨ä¸q
¦pªG±z½T©w¶K¹Ï¸ê®Æ¬O¥¿½T¡A¨º§Úªºµ{¦¡½X¶]¥X¨Óµ²ªG´N¥²µM¬O¿ùªº
¥²¶·¦A¨Ó¬Ý¬Ý­þÃä¥X°ÝÃD¤F
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

«Ü·PÁÂHsieh¤j¤jÀ°¦£,¤£¹L¥Ø«e§ÚÁÙµLªk¤U¸ü©Ò¦³¤j¤j©Ò¦^ÂЪºªþ¥ó,¥u¯àµ¥¨ì¤É¯Å«á¤~¯à¬Ý¨ìµ²ªG
·Q½Ð°ÝHsieh¤j¤j, Excel VBAªºµ{¦¡,¬O§_¯à°µ¨ì¸òC,C++µ¥°ª¶¥»y¨¥¤@¼Ë¼Ò²Õ¤Æªºµ{«×?
³o¸Ì§Ú­n¼á²M»¡©ú,ªþ¥óªº­ì©l¸ê®Æªº½T¬O¶K¹Ïªº¸ê®Æ,§Ú¥u¬O±N­ì©l¸ê®Æ¤¤¤ñ¸û²³æªº¤£½ÆÂøªº¸ê®Æ¶µ­ç°£
¶K¹Ïªº¸ê®Æ¬O§Ú±N­ì©l¸ê®Æ¯d¤U½ÆÂøªº³¡¥÷¨Ó°µ»¡©ú¥Îªº
¦b¼¶¼gµ{¦¡ªº¹Lµ{¤¤·|¹J¨ì°ÝÃDªº¸ê®Æ,°ò¥»¤Wµ{¦¡¼¶¼g¥u­n½ÆÂøªº¯à¼gªº¥X¨Ó,¨ä¥Lªº³£¤£¦¨°ÝÃD
¥i¥H½ÐHsieh¤j¤j¦Û¦æ§R°£¤ñ¸û¤£½ÆÂø¥B²³æªº¸ê®Æ§Y¥i¬Ý¥X¸ò¶K¹Ï¸ê®Æ¬Û¦Pªº¤º®e
ÁÂÁÂ

TOP

¦^´_ 18# white5168
¶K¹Ïªº¸ê®Æ¨Ã¤£¬Oªþ¥ó¤¤CSVªº¸ê®Æ
¨Ì·Ó¤W­z¥ý¶i¥ý¥XÅÞ¿è¸ÕµÛ¼g¬Ý¬Ý¡A§A¦Û¤v¥h¤ñ¹ï¬Ý¬Ýµ²ªG¥¿¤£¥¿½T
play.gif
  1. Sub Get_Data()
  2. Dim Ar(), Ay(), x, y
  3. Set d = CreateObject("Scripting.Dictionary")
  4. Set d1 = CreateObject("Scripting.Dictionary")
  5. Set d2 = CreateObject("Scripting.Dictionary")
  6. fs = ThisWorkbook.Path & "\DataBase.csv"
  7. Open fs For Input As #1
  8. Do Until EOF(1)
  9.    Line Input #1, mystr
  10.    a = Split(mystr, ",")
  11.    If Val(a(0)) > 0 And Val(a(0)) <= [B1] Then
  12.    If IsEmpty(d(a(1))) Then
  13.        For i = 1 To Val(a(3))
  14.           ReDim Preserve Ar(i)
  15.           Ar(i - 1) = Val(a(2))
  16.        Next
  17.        If Val(a(3)) > 0 Then d(a(1)) = Ar
  18.        Else
  19.        Ar = d(a(1))
  20.        s = UBound(Ar)
  21.          For i = 1 To Val(a(3))
  22.            ReDim Preserve Ar(s + i)
  23.            Ar(s + i - 1) = Val(a(2))
  24.          Next
  25.        s = UBound(Ar)
  26.          d(a(1)) = Ar
  27.     End If
  28.     If Val(a(4)) > 0 Then
  29.        If IsEmpty(d1(a(1))) Then
  30.        For i = 1 To Val(a(4))
  31.           ReDim Preserve Ar(i)
  32.           Ar(i - 1) = Val(a(2))
  33.        Next
  34.        If Val(a(4)) > 0 Then d1(a(1)) = Ar
  35.        Else
  36.        Ar = d1(a(1))
  37.        s = UBound(Ar)
  38.          For i = 1 To Val(a(4))
  39.            ReDim Preserve Ar(s + i)
  40.            Ar(s + i - 1) = Val(a(2))
  41.          Next
  42.          d1(a(1)) = Ar
  43.     End If
  44.     End If
  45.     End If
  46.    Erase Ay: Erase Ar
  47. Loop
  48. Close #1
  49. For Each ky In d1.keys
  50.    If IsArray(d1(ky)) Then Ar = d1(ky): x = UBound(Ar) Else x = 0 '¥X³f
  51.    If IsArray(d(ky)) Then Ay = d(ky): y = UBound(Ay) Else y = 0 '¶i³f
  52.    If x = 0 And y > 0 Then '¥u¶i¤£¥X
  53.       For i = 0 To y - 1
  54.         'sp = sp + Ar(i)
  55.         bp = bp + Ay(i)
  56.       Next
  57.       bp = bp / y
  58.       d2(ky) = Array(ky, y, 0, 0, Abs(y - x), y - x, Round(bp, 2), 0)
  59.       bp = 0
  60.       ElseIf y = 0 And x > 0 Then '¥u¥X¤£¶i
  61.       For i = 0 To x - 1
  62.         sp = sp + Ar(i)
  63.       Next
  64.       sp = sp / x
  65.       d2(ky) = Array(ky, y, x, 0, 0, y - x, 0, Round(sp, 2))
  66.       sp = 0
  67.       ElseIf x > 0 And y > 0 Then
  68.          If x > y Then '¥X¤j©ó¶i
  69.          w = 0: w1 = y - x
  70.          For i = 0 To y - 1
  71.          pr = pr + Ar(i) - Ay(i)
  72.          Next
  73.          For j = i To x - 1
  74.          nr = nr + Ar(i)
  75.          Next
  76.          nr = nr / (x - y) '¤£¨¬¶q
  77.          ElseIf x < y Then '¶i¤j©ó¥X
  78.          w1 = 0: w = y - x
  79.          For i = 0 To x - 1
  80.          pr = pr + Ar(i) - Ay(i)
  81.          Next
  82.          For j = i To y - 1
  83.          sr = sr + Ay(i)
  84.          Next
  85.          sr = sr / Abs(x - y) '¤£¨¬¶q
  86.          End If
  87.          
  88.          d2(ky) = Array(ky, y, x, pr, w, w1, Round(sr, 2), Round(nr, 2))
  89.          pr = 0: nr = 0: sr = 0
  90.    End If
  91.    Erase Ay: Erase Ar
  92. Next
  93. [A4:H65536] = ""
  94. [A4].Resize(d2.Count, 8) = Application.Transpose(Application.Transpose(d2.items))
  95. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¥»©«³Ì«á¥Ñ white5168 ©ó 2012-4-30 15:15 ½s¿è

¦p¹Ï¤À§O¬°¸ê®Æ»P³Ì«á¸ê®Æ
³Ì«á¸ê®Æªº³¡¥÷¹ï©ó¤é´Á¬O¥i½Õ¾ãªº,¦p¤é´ÁÅÜ°Ê,«h³Ì«á¸ê®Æ©Ò§e²{ªºµe­±¤]·|§ïÅÜ
¬ÛÃöªºExcelÀɦbªþ¥ó¤¤,¦p¦³¤£²M·¡ªº½Ð¦A´£¥Xµo°Ý
¤p§Ì¤ñ¸û¤£²M·¡¦U¦ì©Ò»Ýªº¸ê°T¨ì¦óºØµ{«×?©Ò¥H¦p¦³«_¥Ç½Ð¦h¦h¨£½Ì

source.JPG (147.79 KB)

¸ê®Æ

source.JPG

finalscreen.JPG (120.04 KB)

§e²{µe­±

finalscreen.JPG

test.rar (2.85 KB)

TOP

        ÀR«ä¦Û¦b : ±o²z­nÄǤH¡A²zª½­n®ð©M¡C
ªð¦^¦Cªí ¤W¤@¥DÃD