|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub lqxs()
Dim mypath$, myName$, sh As Worksheet
Dim i%, ad, nm, cel As Range
Application.ScreenUpdating = False
nm = Array("A304-X")
ad = Array("C5:c17")
For i = 0 To UBound(nm)
Sheets(nm(i)).Range(ad(i)).ClearContents
Next
mypath = ThisWorkbook.Path & "\"
myName = Dir(mypath & "*.xls?")
Do While myName <> ""
If InStr(myName, "报表--乡镇常规报表2019222") = 0 Then
With GetObject(mypath & myName)
For i = 0 To UBound(nm)
Set sh = .Sheets(nm(i))
With Sheets(nm(i))
For Each cel In sh.Range(ad(i))
If cel.Value <> "" Then
.Range(cel, Address) = .Range(cel.Address) + cel.Value
End If
Next
End With
Next
.Close False
End With
End If
myName = Dir
Loop
Application.ScreenUpdating = True
End Sub
这段代码是我从其他帖子里复制来的,自己做了更改,但是运行出错,请各位大神指点
|
|