|
本帖最后由 gujiejack2 于 2013-1-13 02:09 编辑
我也新手,我试着写了一下。
- Sub 数据分析()
- Dim FileName, wb As Workbook, arr1()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- FileName = Dir(ThisWorkbook.Path & "\*.xls")
- Do While FileName <> ""
- If FileName <> ThisWorkbook.Name Then
- fn = ThisWorkbook.Path & "" & FileName
- Workbooks.Open fn
- ends = ActiveSheet.Cells(Rows.Count, "a").End(xlUp).Row
- arr = Range("a2:g" & ends)
- For i = 1 To UBound(arr)
- ReDim Preserve arr1(1 To 7, 1 To n + 1)
- If arr(i, 4) <> 0 Then
- n = n + 1
- arr1(1, n) = arr(i, 1)
- arr1(2, n) = arr(i, 2)
- arr1(3, n) = arr(i, 3)
- arr1(4, n) = arr(i, 4)
- arr1(5, n) = arr(i, 5)
- arr1(6, n) = arr(i, 6)
- arr1(7, n) = arr(i, 7)
- End If
- Next
- Else: GoTo 100
- End If
- ActiveWorkbook.Close True
- FileName = Dir
- Loop
- 100:
- Sheet1.[a1].Resize(n, 7) = Application.Transpose(arr1)
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码
|
|