|
楼主 |
发表于 2015-12-21 18:02
|
显示全部楼层
谢谢,可以解决问题,在我这个代码上面有办法直接加判定不
- Sub tt()
- Dim ws As Workbook, sht As Worksheet, rng As Range, rnd As Range
- Dim path$, myname$, d, k&
- Application.ScreenUpdating = False
- path = ThisWorkbook.path & ""
- d = Dir(path & "*.xls")
- k = 1
- With ActiveSheet
- [a2:z5000].ClearContents
- Do While d <> ""
- If d <> ThisWorkbook.Name Then
- k = k + 1
- Set ws = Workbooks.Open(path & d)
- .Cells(k, 3) = Replace(ws.Name, ".xls", "")
- Set rng = ws.Sheets("表一").Range("b:b").Find(What:="*合 计*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 5) = rng.Offset(0, 7)
- Set rng = ws.Sheets("表二").Range("b:b").Find(What:="*主要材料费*", lookat:=xlPart)
- Set rnd = ws.Sheets("表四(乙供材)").Range("b:b").Find(What:="*总 计*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 6) = rng.Offset(0, 2) - rnd.Offset(0, 5)
- Set rng = ws.Sheets("表四(乙供材)").Range("b:b").Find(What:="*总 计*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 7) = rng.Offset(0, 5)
- Set rng = ws.Sheets("表五甲").Range("b:b").Find(What:="*安全生产费*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 9) = rng.Offset(0, 4)
- Set rng = ws.Sheets("表五甲").Range("b:b").Find(What:="*建设用地及综合赔补费*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 10) = rng.Offset(0, 4)
- Set rng = ws.Sheets("表二").Range("b:b").Find(What:="*建筑安装工程费*", lookat:=xlPart)
- Set rnd = ws.Sheets("表二").Range("b:b").Find(What:="*主要材料费*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 8) = rng.Offset(0, 2) - rnd.Offset(0, 2)
- Set rng = ws.Sheets("表五甲").Range("b:b").Find(What:="*勘察设计费*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 11) = rng.Offset(0, 4)
- Set rng = ws.Sheets("表五甲").Range("b:b").Find(What:="*建设工程监理费*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 12) = rng.Offset(0, 4)
- Set rng = ws.Sheets("表一").Range("b:b").Find(What:="*合 计*", lookat:=xlPart)
- If Not rng Is Nothing Then .Cells(k, 25) = rng.Offset(0, 2)
- ws.Close False
- End If
- d = Dir
- Loop
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|