A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
this is all great however how do I get to these steps. I am not very excel saavy. Can you provided step by step and how to get to each screen. Do I need to create a new workbook?
OK,
Please, try the following steps:
- Make a copy of your workbook and save it as an Excel Macro-Enabled Workbook (*.xlsm)
- On your keyboard, press: ALT+F11. This will prompt the VBA edit panel. Then Double-click on "Thisworkbook"
- Copy and paste the code into the Workbook's Open Procedure VBA editor as shown in the picture below.
This is the code:
Private Sub Workbook_Open()
Dim sh As Worksheet
Dim Lr As Long
Dim x As Long
Dim cnt As Long
Application.ScreenUpdating = False
''' Loop thru all the sheets in the workbook
For Each sh In ThisWorkbook.Worksheets
With sh
''' Find the last used row in column E
Lr = .Range("E" & Rows.Count).End(xlUp).Row
For x = 7 To Lr
If IsDate(.Range("E" & x)) Then
''' Expiration date checking and data removing
If .Range("E" & x).Value <= Date Then
.Range("E" & x).EntireRow.Delete
cnt = cnt + 1 ''' counting
End If
End If
Next x
End With
Next sh
Application.ScreenUpdating = True
'''Reporting
MsgBox Prompt:="Total Absence removed:= " & cnt, Title:="REMOVAL REPORT - DATE: " & Date
End Sub
- Then save all the changes and close the file.
- Open the file/workbook once again, and the macro code will execute upon opening.
IMPORTANT NOTE:
The code was written assuming the following:
- All the sheet tabs have a similar structure, with the "Occasion Absence Removed" field in column E as the field that calculates the 9-month date from column A.
- The data values start in row 7 downwards.
I hope this helps you and gives a solution to your problem
Do let me know if you need more help
Jeovany