I need a macro on button click that will create copy of active workbook, clear some cells in first 3 sheets of this copy file and save it. Before saving it also removes filtermode on sheet "sul".
I wrote this code. It creates copy of workbook but doesn't clears cells at all and doesn't removes filtermode in copy file. After code execution copy file is open and source file is closed.
Please help to correct it. Thanks.
Code
Sub Button1_Click()
saxeli1 = "00.00." & Year(Date) & ".xlsm"
If Len(Dir(ThisWorkbook.Path & "\" & saxeli1)) = 0 Then
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & saxeli1
Workbooks.Open (ThisWorkbook.Path & "\" & saxeli1)
For i = 1 To 3
Workbooks(ThisWorkbook.Path & "\" & saxeli1).Sheets(i).Range("D3:CY202").Clear
Next
Workbooks(ThisWorkbook.Path & "\" & saxeli1).Sheets("sul").FilterMode = False
Workbooks(ThisWorkbook.Path & "\" & saxeli1).Close SaveChanges:=True
End If
End Sub
Display More