- ©«¤l
- 4901
- ¥DÃD
- 44
- ºëµØ
- 24
- ¿n¤À
- 4916
- ÂI¦W
- 273
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 20xx
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥x¥_
- µù¥U®É¶¡
- 2010-4-30
- ³Ì«áµn¿ý
- 2024-12-17
|
¦^´_ 18# white5168
¶K¹Ïªº¸ê®Æ¨Ã¤£¬Oªþ¥ó¤¤CSVªº¸ê®Æ
¨Ì·Ó¤Wz¥ý¶i¥ý¥XÅÞ¿è¸ÕµÛ¼g¬Ý¬Ý¡A§A¦Û¤v¥h¤ñ¹ï¬Ý¬Ýµ²ªG¥¿¤£¥¿½T
- Sub Get_Data()
- Dim Ar(), Ay(), x, y
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- fs = ThisWorkbook.Path & "\DataBase.csv"
- Open fs For Input As #1
- Do Until EOF(1)
- Line Input #1, mystr
- a = Split(mystr, ",")
- If Val(a(0)) > 0 And Val(a(0)) <= [B1] Then
- If IsEmpty(d(a(1))) Then
- For i = 1 To Val(a(3))
- ReDim Preserve Ar(i)
- Ar(i - 1) = Val(a(2))
- Next
- If Val(a(3)) > 0 Then d(a(1)) = Ar
- Else
- Ar = d(a(1))
- s = UBound(Ar)
- For i = 1 To Val(a(3))
- ReDim Preserve Ar(s + i)
- Ar(s + i - 1) = Val(a(2))
- Next
- s = UBound(Ar)
- d(a(1)) = Ar
- End If
- If Val(a(4)) > 0 Then
- If IsEmpty(d1(a(1))) Then
- For i = 1 To Val(a(4))
- ReDim Preserve Ar(i)
- Ar(i - 1) = Val(a(2))
- Next
- If Val(a(4)) > 0 Then d1(a(1)) = Ar
- Else
- Ar = d1(a(1))
- s = UBound(Ar)
- For i = 1 To Val(a(4))
- ReDim Preserve Ar(s + i)
- Ar(s + i - 1) = Val(a(2))
- Next
- d1(a(1)) = Ar
- End If
- End If
- End If
- Erase Ay: Erase Ar
- Loop
- Close #1
- For Each ky In d1.keys
- If IsArray(d1(ky)) Then Ar = d1(ky): x = UBound(Ar) Else x = 0 '¥X³f
- If IsArray(d(ky)) Then Ay = d(ky): y = UBound(Ay) Else y = 0 '¶i³f
- If x = 0 And y > 0 Then '¥u¶i¤£¥X
- For i = 0 To y - 1
- 'sp = sp + Ar(i)
- bp = bp + Ay(i)
- Next
- bp = bp / y
- d2(ky) = Array(ky, y, 0, 0, Abs(y - x), y - x, Round(bp, 2), 0)
- bp = 0
- ElseIf y = 0 And x > 0 Then '¥u¥X¤£¶i
- For i = 0 To x - 1
- sp = sp + Ar(i)
- Next
- sp = sp / x
- d2(ky) = Array(ky, y, x, 0, 0, y - x, 0, Round(sp, 2))
- sp = 0
- ElseIf x > 0 And y > 0 Then
- If x > y Then '¥X¤j©ó¶i
- w = 0: w1 = y - x
- For i = 0 To y - 1
- pr = pr + Ar(i) - Ay(i)
- Next
- For j = i To x - 1
- nr = nr + Ar(i)
- Next
- nr = nr / (x - y) '¤£¨¬¶q
- ElseIf x < y Then '¶i¤j©ó¥X
- w1 = 0: w = y - x
- For i = 0 To x - 1
- pr = pr + Ar(i) - Ay(i)
- Next
- For j = i To y - 1
- sr = sr + Ay(i)
- Next
- sr = sr / Abs(x - y) '¤£¨¬¶q
- End If
-
- d2(ky) = Array(ky, y, x, pr, w, w1, Round(sr, 2), Round(nr, 2))
- pr = 0: nr = 0: sr = 0
- End If
- Erase Ay: Erase Ar
- Next
- [A4:H65536] = ""
- [A4].Resize(d2.Count, 8) = Application.Transpose(Application.Transpose(d2.items))
- End Sub
½Æ»s¥N½X |
|