|
|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
sub aa
Dim MyPath$, MyName$, sh As Worksheet
Set sh = ActiveSheet
Dim sht As Worksheet
Dim r%
‘mypath路径自己设置’
MyPath = "C:\Documents and Settings\hlc\桌面\学校调资录入模板" & "\"‘
MyName = Dir$(MyPath & "*.xls")
Application.ScreenUpdating = False
Do While MyName <> ""
Workbooks.Open MyPath & MyName
For Each sht In Worksheets
With sht
r = .[a65536].End(3).Row + 1
q = r - 3
If .Cells(r - 1, 1) <> "合计" Then
Range(.Cells(3, 9), .Cells(r - 1, 9)) = "=IF(AND(RC[-3]<=0,RC[-1]<=0),,IF((RC[-5]-RC[-10])<0,""不能为负数"",RC[-5]-RC[-10]))"
Range(.Cells(3, 14), .Cells(r - 1, 14)) = "=RC[-5]-RC[-10]"
Range(.Cells(3, 17), .Cells(r - 1, 17)) = "=RC[-2]+RC[-1]"
Range(.Cells(r, 4), .Cells(r, 17)).Formula = "=SUM(R[-" & q & "]C:R[-1]C)"
Range(.Cells(r, 1), .Cells(r, 3)).Merge
Range(.Cells(r, 1), .Cells(r, 3)).Value = "合计"
Range(.Cells(r, 1), .Cells(r, 3)).HorizontalAlignment = xlCenter
Range(.Cells(r, 1), .Cells(r, 17)).Borders.LineStyle = 1
End If
End With
Next
Workbooks(MyName).Close True
MyName = Dir
Loop
MsgBox "已完成"
Application.ScreenUpdating = True
end sub |
|