Im trying to use this cod for checking expiry date. Im using Code before to open different file and copy cells as below. Please can any one help why I have Run time Error 13 Type mismatch. Any ideas ?? I was trying to put If empty cell exit sub but still that same :(
Set wkbData = Workbooks.Open(Filename, , True)
wkbData.Sheets("IBL").Range("H1:I100").Cells.Copy
wkbSource.Sheets("Expiry Date").Range("A1").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
wkbData.Close
Dim LRow As Integer
Dim LResponse As Integer
Dim LName As String
Dim LDiff As Integer
Dim LDays As Integer
LRow = 2
LDays = 31
While LRow < 200
If Len(Sheets("Expiry Date").Range("A" & LRow).Value) > 0 Then
If Len(Sheets("Expiry Date").Range("A" & LRow).Value) = "" Then Exit Sub
LDiff = DateDiff("d", Date, Sheets("Expiry Date").Range("A" & LRow).Value)
If (LDiff > 0) And (LDiff <= LDays) Then
LName = Sheets("Expiry Date").Range("B" & LRow).Value
LResponse = MsgBox("The Juice " & LName & " will expire in " & LDiff & " days.", vbCritical, "Warning")
End If
End If
LRow = LRow + 1
Worksheets(1).Activate
Wend
End Sub
I'm not positive that this is the exact problem but I think that your syntax on DateDiff may be off. I understand it should look something like this: DateDiff(DateInterval.Day, Now, Sheets("Expiry Date").Range("A" & LRow).Value)