?type mismatch in if statement


Posted by Robin T on April 25, 2001 2:57 PM

The value of a66 is "f" but the if statement causes an error.

Sub Exercise()
Dim Exercise As Range
Dim CalorieBurn As Range
Dim TimeExercise As Range
Set Exercise = Application.InputBox _
(Prompt:="Select any exercise range", Title:="Exercise", Type:=8)
Set CalorieBurn = Range("c11")
Set TimeExercise = Range("c9")
Exercise.Select

If Range("a66").Value = "f" Or "F" Then
Exercise(Cells(2, 0)).Select
CalorieBurn.Value = TimeExercise.Value / 60 * ActiveCell

That is as far as I get and get a type mismatch but the value shows "f".

Thanks,
--robin t



Posted by Dave Hawley on April 25, 2001 3:06 PM


Hi Robin

Try this

Option Compare Text
Sub Exercise()
Dim Exercise As Range
Dim CalorieBurn As Range
Dim TimeExercise As Range
Set Exercise = Application.InputBox _
(Prompt:="Select any exercise range", Title:="Exercise", Type:=8)
Set CalorieBurn = Range("c11")
Set TimeExercise = Range("c9")
Exercise.Select

If Range("a66").Value = "f" Or Range("a66").Value = "F" Then
Exercise(Cells(2, 0)).Select
CalorieBurn.Value = TimeExercise.Value / 60 * ActiveCell

That is as far as I get and get a type mismatch but the value shows "f".


Excel will not be case sensitive UNLESS you set the Option Compare to binary, the default is "Option Compare Text" (not case sensitive).


I have put the "Option Compare Text" at the top of the procedure just in case! So you can really remove the second IF.


Dave


OzGrid Business Applications