Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

?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


Check out our Excel VBA Resources

Re: ?type mismatch in if statement

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


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.