Type Mismatch error

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi. I am having a problem I am sure there is a very
simple answer to. In the following code, I receive
a "Type Mismatch" Error when the IF statement is
excecuted. Can anyone tell me what I am doing wrong?

Thanks,
Mike.

Sub temp3()
Dim IPRg As Range
Set IPRg = Columns(4)
Dim temp
For Each Cell In IPRg
If IPRg.Cells.Value = "Bob" Then
IPRg.Cells.Select
End If
Next
End Sub
 
Mike,

Try the following

For Each Cell In IPRg.Cells
If Cell.Value = "Bob" Then
Cell.Select
End If
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Thanks, Chip!
-----Original Message-----
Mike,

Try the following

For Each Cell In IPRg.Cells
If Cell.Value = "Bob" Then
Cell.Select
End If
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





.
 
you might want a slight modification

For Each Cell In IPRg.Cells
If Cell.Value = "Bob" Then
Cell.Select
Exit For
End If
Next

looping through 65536 cells can take a while and there is not reason to do
it after you find bob.
 
Back
Top