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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is IsError appropriate? Not proceeding to Then statement 1

Status
Not open for further replies.

skitrumpet

Technical User
Aug 26, 2010
5
GB
Hi,

I am trying to write a procedure that if a variable (portfolio), isn't found in a range (term_portfolio), then find an alternative variable (area) in an alternative range (term_area).

The problem is that using the following does not follow the Then logic when an error was expected, i.e. no match in term_portfolio.

I'd be very grateful if someone would help me with what I'm missing.


I've tried the following:

Application.Goto reference:="term_portfolio"

If IsError(Selection.Find(what:=portfolio)) = True Then
Application.Goto reference:="term_area"
Selection.Find(what:=area).Activate
reporting_category = ActiveCell.Offset(0, 2)
Sheets("Deals").Select
ActiveCell = reporting_category
Else
Selection.Find(what:=portfolio).Activate
reporting_category = ActiveCell.Offset(0, 1)
Sheets("Deals").Select
ActiveCell = reporting_category

End If



Many thanks in advance

Adam
 
isError() is a function that will return either True or False, you can't assign a value to it. Why don't you try:

If IsError(Selection.Find(what:=portfolio)) Then
....
 
Selection.Find returns a Range Object or, if not found, Nothing. Checking for 'Error' is the wrong thing to do. Try, instead, ...

Code:
[blue]If (Selection.Find(what:=portfolio) Is Nothing) Then[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
That's perfect.

Thanks very much for your help.


Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top