|
Sub test()
本帖最后由 yangyangzhifeng 于 2012-12-19 10:49 编辑
放眼TOT 发表于 2012-12-18 23:57
这个附件就是原始TXT数据的其中一个,
另一个附件是我自己录制的宏来处理EXCEL达到我要的那两个量的代码, ...
试试看,只计算你要求的字段,没有导入txt- Sub test()
- Dim Arr, k&, ph$, fl$, sp1#, sp2#, brr, i&
- Dim crr(), n&
- ph = ThisWorkbook.Path & ""
- fl = Dir(ph & "*.txt")
- Do While fl <> ""
- Open ph & fl For Input As #1
- Arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
- Reset
- k = UBound(Arr)
- sp1 = 0: sp2 = 0
- For i = 0 To k
- brr = Split(Arr(i), ",")
- sp1 = sp1 + Val(brr(42))
- sp2 = sp2 + Abs(Val(brr(6)) - (Val(brr(24)) + Val(brr(25))) / 2) / Val(brr(6))
- Next
- sp1 = sp1 / (k + 1): sp2 = sp2 / (k + 1)
- n = n + 1
- ReDim Preserve crr(1 To 3, 1 To n)
- crr(1, n) = brr(0)
- crr(2, n) = sp1
- crr(3, n) = sp2
- fl = Dir
- Loop
- Sheet2.Range("a2:c" & Rows.Count).ClearContents
- Sheet2.Range("a2").Resize(n, 3) = Application.Transpose(crr)
- End Sub
复制代码 |
|