I'm coding a function to compare two dates. My problem is with the bold line. When the code executes I get an overflow error. After several searches on the internet I understood that this type of error could occur when using an interger instead of a long one, which is not my case.
I've got about 235 thousand lines to process and I'm in a bit of a rush to finish programming this function before the end of the month.
Does anyone have any idea why this error occurred?
This is my code :
Public Function date_dif(sheet As String, number As Integer, colonnetarget As Integer, colonnedate1 As Integer, Optional colonnedate2 As Integer)
Dim last_row As Long
Dim sht, sht2 As Worksheet
Dim ligne As Integer
Dim formule As String
Dim crit1, crit2 As String
Set sht = ThisWorkbook.Worksheets(sheet)
last_row = sht.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
If colonnedate2 <> 0 Then
**For ligne = 2 To last_row**
sht.Cells(ligne, colonnetarget).Value = DateDiff("d", sht.Cells(ligne, colonnedate1).Value, sht.Cells(ligne, colonnedate2).Value)
Next
Else
For ligne = number To last_row
sht.Cells(lignxe, colonnetarget).Value = DateDiff("d", sht.Cells(ligne, colonnedate1).Value, Now())
Next
End If
End Function