Check Expiry dates from multiple sheets with a pop up box

Kjjb

New Member
Joined
Dec 26, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi ,
Surely there must be a thread for my query , but cannot seem to find it .Appreciate your help.
I have a worksheet with 4 sheets named "D1D","D2D","D3D","Misc" . I need to write a VBA to check all the 4 sheets for expiry date ( today()-30) in column E ( range E 7:E135) and then pop message should state Certificates have expired. The pop up box/check should be done when I open the workbook.
Appreciate your help.

Thanks in advance
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
In the VBA project explorer window double click to ThisWorkbook on the left pane and paste the code.
VBA Code:
Private Sub Workbook_Open()
  Dim wsNames() As string
  wsNames = Split("D1D,D2D,D3D,Misc", ",")
  For i = 0 To 3
    With Worksheets(wsNames(i))
      For j = 7 to 135
        If .Cells(j, 5).Value > Now()-30 Then
          MsgBox "Sheet " & wsNames(i) & " Date E" & j & " has expired."
        End If
      Next
    End With
  Next
End Sub
 
Upvote 0
Hi Flashbond,
THANK YOU for the prompt reply.

However i am getting a runtime error 9 , script out of range
With Worksheets(wsNames(i))
Please assist
Thanks
 
Upvote 0
This error is caused if you don't have sheets named as "D1D","D2D","D3D" or "Misc".
 
Upvote 0
VBA Code:
Sub works()
      Dim names
      Dim k As Integer
      names = Array("D1D", "D2D", "D3D", "Misc")
      Dim i As Long
      For Each names In Worksheets
            For i = 7 To 135
                If names.Range("E" & i) = Date - 30 Then
                    MsgBox "Sheet name: " & names.Name & vbNewLine & names.Range("E" & i).Address & " Certificates have expired"
                End If
            Next i
     Next names
End Sub
 
Upvote 0
This error is caused if you don't have sheets named as "D1D","D2D","D3D" or "Misc"

I have just realised it works only for sheet D1D .. then give a run time error. I have attached an image
 

Attachments

  • Screenshot 2022-12-26 184901.jpg
    Screenshot 2022-12-26 184901.jpg
    186.6 KB · Views: 12
Upvote 0
VBA Code:
Sub works()
      Dim names
      Dim k As Integer
      names = Array("D1D", "D2D", "D3D", "Misc")
      Dim i As Long
      For Each names In Worksheets
            For i = 7 To 135
                If names.Range("E" & i) = Date - 30 Then
                    MsgBox "Sheet name: " & names.Name & vbNewLine & names.Range("E" & i).Address & " Certificates have expired"
                End If
            Next i
     Next names
End Sub
VBA Code:
Sub works()
      Dim names
      Dim k As Integer
      names = Array("D1D", "D2D", "D3D", "Misc")
      Dim i As Long
      For Each names In Worksheets
            For i = 7 To 135
                If names.Range("E" & i) = Date - 30 Then
                    MsgBox "Sheet name: " & names.Name & vbNewLine & names.Range("E" & i).Address & " Certificates have expired"
                End If
            Next i
     Next names
End Sub
Hi ,

Tried the code ..nothing happens.
 
Upvote 0
I have just realised it works only for sheet D1D .. then give a run time error. I have attached an image
Hi ,

Did a few adjustment to the sheet and now only sheets Misc & various do not work. Getting a run time error ??
Please advise
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top