Must Manually Reformat Date Column Due to Type Mismatch Run-Time Error

  • Thread starter Thread starter steveski
  • Start date Start date
S

steveski

I have some code that steps through a Data Entry sheet and polls
column of dates (Column “I”). I get a “: Type mismatch: at the “Sdate
Cells(i, "I").Value” statement. If I go to the Data Entry sheet, selec
the entire column I, and format the cells as Date format, then the nex
time I run the code I will not get the error. However, the next time
run the code after that I will get the error again and I must go bac
and reformat the column to Date format. Do you have any ideas as t
what may be causing this? (I am using Excel 2000.)

Thanks.

Dim Sdate As Date
With Sheets("Data Entry").Range("PTSource")
LastRow = .Rows.Count
For i = 2 To LastRow
Sdate = Cells(i, "I").Value
Etc
 
Hi Steve

Show your code please

LastRow = .Rows.Count
This is not the last row of the range now.
It will give you the rows count of the range
Do you know this?

See my example for the last row in the range
 
Here's my code.

With Sheets("Data Entry").Range("PTSource")
LastRow = .Rows.Count
For n = 2 To LastRow
Sdate = Cells(n, "I").Value
Edate = Cells(n, "Q").Value
If (Month(Sdate) = tma) And (Year(Sdate) = ytma) Then
If Cells(n, "H").Value = "E" Then
c1 = c1 + 1
ElseIf Cells(n, "H").Value = "R1" Then
c2 = c2 + 1
ElseIf Cells(n, "H").Value = "R2" Then
c3 = c3 + 1
ElseIf Cells(n, "H").Value = "R3" Then
c4 = c4 + 1
End If

This followed by more similar else if statements.
So, is Last Row beyond teh last populated row, and is would thi
explain why I'm getting a Type mismatch
 
Back
Top