ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel and VBA - If and Find Expressions (https://www.excelbanter.com/excel-programming/396440-excel-vba-if-find-expressions.html)

Ronan

Excel and VBA - If and Find Expressions
 
Hello

I am trying to use an If statement to find an piece of text and then go to
the cell that contains that text. I have, as part of the if statement, an
else statement that just cancels the expression and does something else if it
cant find the iece of text. However, the expression doesnt seem to work when
VB cant find any cell with the specific text and it just comes back with a
run time error. Does anyone know if there is a proper way of putting a "find"
expression inside an "if" expression or maybe a better way of doing what I am
trying to do?


Mike H

Excel and VBA - If and Find Expressions
 
One way

Sub findit()
Set myRange = Range("A1:C20") 'Change to suit
For Each c In myRange
If c.Value = "myvalue" Then
c.Select
found = True
End If
Next
If found = False Then MsgBox ("myvalue" & " Not found")
End Sub

Mike

"Ronan" wrote:

Hello

I am trying to use an If statement to find an piece of text and then go to
the cell that contains that text. I have, as part of the if statement, an
else statement that just cancels the expression and does something else if it
cant find the iece of text. However, the expression doesnt seem to work when
VB cant find any cell with the specific text and it just comes back with a
run time error. Does anyone know if there is a proper way of putting a "find"
expression inside an "if" expression or maybe a better way of doing what I am
trying to do?


Bob Phillips

Excel and VBA - If and Find Expressions
 
Post the code.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Ronan" wrote in message
...
Hello

I am trying to use an If statement to find an piece of text and then go to
the cell that contains that text. I have, as part of the if statement, an
else statement that just cancels the expression and does something else if
it
cant find the iece of text. However, the expression doesnt seem to work
when
VB cant find any cell with the specific text and it just comes back with a
run time error. Does anyone know if there is a proper way of putting a
"find"
expression inside an "if" expression or maybe a better way of doing what I
am
trying to do?





All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com