dimanche 19 avril 2015

Hallo i try to make a Macro to warn when a record will expire within 30 for example.

Private Sub Workbook_Open()



Dim LRow As Integer
Dim LResponse As Integer
Dim LName As String
Dim LDiff As Integer
Dim LDays As Integer

LRow = 2

'Warning - Number of days to check for expiration
LDays = 50

'Check the first 37 rows in column S
While LRow < 37

'Only check for expired certificate if value in column S is not blank
If Len(Sheets("Sheet1").Range("S" & LRow).Value) > 0 Then

LDiff = DateDiff("d", Date, Sheets("Sheet1").Range("S" & LRow).Value)
If (LDiff > 0) And (LDiff <= LDays) Then
'Get name
LName = Sheets("Sheet1").Range("B" & LRow).Value
LResponse = MsgBox("The insurance certificate for " & LName & " will expire in " & LDiff & " days.", vbCritical, "Warning")
End If
End If

LRow = LRow + 1
Wend


End Sub


Icopy this code from internet but exery time it give me "runtime error 13". i am working in excel 2010. In "c" coloumn i have the expires date and in "B" the names of my customer. can you help me please?


Aucun commentaire:

Enregistrer un commentaire