|
楼主 |
发表于 2017-6-25 10:40
|
显示全部楼层
Sub g()
mypath = ActiveWorkbook.Path & "\"
myname = "损益表"
myfile = Dir(mypath & "*.xls")
m = 2
n = 1
Do Until Len(myfile) = 0
If myfile <> myname Then
Workbooks.Open Filename:=mypath & myfile
wbname = Left(myfile, InStr(myfile, ".") - 1)
lastcol = Cells(2, Columns.Count).End(xlToLeft).Column
lastrow = Cells(Rows.Count, 1).End(3).Row
arr = Range(Cells(2, 1), Cells(lastrow, lastcol))
ActiveWorkbook.Close savechanges:=flase
End If
Cells(2, n).Resize(UBound(arr), UBound(arr, 2)) = arr
ncol = Cells(2, Columns.Count).End(xlToLeft).Column
Range(Cells(1, m), Cells(1, ncol)).Merge
Cells(1, m).HorizontalAlignment = xlCenter
Cells(1, m) = wbname
m = m + UBound(arr, 2)
n = n + UBound(arr, 2)
Erase arr
myfile = Dir
Loop
ActiveSheet.UsedRange.Borders.LineStyle = 7
For Each Rng In Range(Cells(2, 1), Cells(2, Columns.Count).End(xlToLeft))
If Rng <> "" Then Rng.Value = Application.Text(Rng.Value, "h:mm:ss")
Next Rng
End Sub
这是蓝老师之前作出的宏,想加个参数,比如:合并损益表的时候就只横向拼接损益表,损益表工作簿名称是一样的 |
|