Range("B1").Select
Columns("B:B").Select
Selection.Find(What:="Grand Total", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
a = ActiveCell.Address(0, 0)
Range("B1").Select
On Error GoTo er
Columns("B:B").Select
Selection.Find(What:="Opt Total", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
b = ActiveCell.Address(0, 0)
Range("B100").Value = "=IfError(" & a & "-" & b & ",0)"
Range("B100").Select
Selection.Copy
Range(Selection, Selection.End(xlToRight)).Select
Selection.PasteSpecial xlPasteFormulas
Range("B100").Select
ActiveCell.Value = "New Total"
ActiveWorkbook.SaveAs Filename:= "xyz"
ActiveWindow.Close (True)
Workbooks(vb).Activate
Next i
MsgBox "Files are ready"
er:
Range("B100").Value = "=" & a
Range("B100").Select
Selection.Copy
Range(Selection, Selection.End(xlToRight)).Select
Selection.PasteSpecial xlPasteFormulas
Range("B100").Select
ActiveCell.Value = "New Total"
ActiveWorkbook.SaveAs Filename:= "xyz"
ActiveWindow.Close (True)
Workbooks(vb).Activate
Next i
MsgBox "Files are ready"
End Sub
插入Exit Sub
:
MsgBox "Files are ready"
Exit Sub
er: