Question : Error 2029 trying to get the serial date of date formatted as "general"


I'm taking a beginning date and an ending date via msgbox from user which I convert to serial date then I need to show only data between that range of date.  The format of the cells that contain the dates are formatted as "general" so I apply date serial function and get error 2029.   I can't figure it out!!
I attach spreadsheet
I get the error at this line
If (cell.Value) < StartDate Or (cell.Value) > EndDate
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
Sub DateRange()
Dim d As Double
Dim i As Variant

Dim cel As Range, celStart As Range, celEnd As Range, rg As Range, del As Range
Dim StartDate As Long, EndDate As Long

StartDate = CLng(CDate(Application.InputBox("Please enter starting date", Type:=2)))
If StartDate = 0 Then Exit Sub
EndDate = CLng(CDate(Application.InputBox("Please enter ending date", Type:=2)))
If EndDate = 0 Then Exit Sub

    Range("J2").Select
  'try using the date serial
    Range("J2").FormulaR1C1 = "=DATESERIAL(MID(J2,7,4),LEFT(J2,2),MID(J2,4,2))"

'
 Set rg = Range("J2") 'First date cell
 Set rg = Range(rg, Cells(Rows.Count, rg.Column).End(xlUp)) 'All the dates in that column

If EndDate < StartDate Then
    d = EndDate
    EndDate = StartDate
    StartDate = d
End If

Application.ScreenUpdating = False
Set rng = Intersect(Range("J:J"), ActiveSheet.UsedRange)
 For Each cell In rng
       cell.Activate
    If (cell.Value) < StartDate Or (cell.Value) > EndDate Then
       If del Is Nothing Then
          Set del = cell
          Else: Set del = Union(del, cell)
      End If
   End If
Next cell

 On Error Resume Next
 del.EntireRow.Delete

Application.ScreenUpdating = True
  
    
End Sub
Attachments:
 
spreadsheet data
 

Answer : Error 2029 trying to get the serial date of date formatted as "general"

IDK, server has not been restarted...but it seems to have kept the settings after third attempt.
Random Solutions  
 
programming4us programming4us