|
汇总表和下发单位的表格式是一模一样的,发给单位的表,每个单位只填自己的行,然后汇总,我自己写了一个,总觉得不是很好,求更好的代码。单位有100多家,其实下发表做成每个单位一行即可,只是经常遇到这样的求助,希望大家出手相助。
- Sub ch()
- Dim Mypath$, Myname$, x, wb As Workbook, sh As Worksheet, rg As Range
- Application.ScreenUpdating = False
- Range("b2:e11") = ""
- Mypath = ThisWorkbook.Path & ""
- Myname = Dir(Mypath & "*.xls")
- Do While Myname <> ""
- If Myname <> ThisWorkbook.Name Then
- Set wb = Workbooks.Open(Mypath & Myname)
- Set sh = wb.Sheets(1)
- For Each rg In sh.Range("b2:e11")
- If rg.Value <> "" Then
- x = rg.Row
- arr = sh.Range("b" & x & ":e" & x)
- Workbooks("汇总.xls").Sheets(1).Range("b" & x & ":e" & x) = arr
- Exit For
- End If
- Next
- wb.Close False
- End If
- Myname = Dir
- Loop
- Application.ScreenUpdating = True
- MsgBox "完成"
- End Sub
复制代码
|
|