Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Datatype

Status
Not open for further replies.

techie88

Programmer
Aug 30, 2011
8
US
I am getting a type mismatch error for rTime at
If (TimeValue(rTime) >= TimeValue(lbl4AM) And TimeValue(rTime) < TimeValue(lbl11AM)) Then

Can anyone help me solve this problem? What datatype is rTime supposed to be declared as?

Sub CreateTimeBlocks()
Dim iRow As Integer, iColumn As Integer, jRow As Integer, jColumn As Integer
iRow = 1
iColumn = 3
jRow = 2
jColumn = 2
Dim rTime As String

Do While iRow < 37
Workbooks("Book1.xlsm").Sheets("Sheet1").Activate
Do Until IsEmpty(Cells(iRow, iColumn))
rTime = Cells(iRow, iColumn)
If (TimeValue(rTime) >= TimeValue(lbl4AM) And TimeValue(rTime) < TimeValue(lbl11AM)) Then
Workbooks("Book1.xlsm").Sheets("Sheet2").Activate
Cells(jRow, jColumn) = Cells(jRow, jColumn) + 1
Else
Workbooks("Book1.xlsm").Sheets("Sheet3").Activate
Cells(jRow, jColumn) = Cells(jRow, jColumn) + 1
End If
Workbooks("Book1.xlsm").Sheets("Sheet1").Activate
iColumn = iColumn + 1
Loop
jRow = jRow + 1
iColumn = 3
iRow = iRow + 1
Loop

End Sub
 
What is the value of rTime when the error raises ?
You try to use the IsDate function to be sure that rTime contains legal value.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The value of rTime appears to be a string "0.29166666667".

Can you give me an example of how to use IsDate function? It seems like most of the examples on the web are complaining that IsDate function is not working.
 
never mind, i fixed the problem. the format in the sheet cell was not correct. i had to reset it to time format.
 


faq68-5827

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top