iserror and better

oaishm

Board Regular
Joined
Jan 30, 2009
Messages
97
I have this statement

Code:
iif(iserror(left(long_text,instr(long_text,"/")),long_text,left(long_text,instr(long_text,"/")))

so if long_text is asdfsf/sdfs
it will return asdfsf

and if its
asdfsf
it will return asdfsf

But alas... When there's no "/" in the long_text, instr evaluates to 0 and left throws an error and iserror is only good for numeric items. Is there something better than iserror, or do I have to do something like instr()>0.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Yes, should work with Instr()
=IIF(Instr(1,long_text,"/")>0,Left(long_text,Instr(1,long_text,"/")-1),long_text)
 
Upvote 0
There's no catchall iserror function? I've got to test every input of a string of functions and not just let the error trickle down until the iserror catches it at the end of the function?
 
Upvote 0
I don't think there is a catchall iserror function but I could be wrong. You probably could create such a function with VBA. But I'm not sure what you mean by a string of functions or why an error would be caught at the "end of the function". The example we looked at above seems straightforward and effective to me.

ξ
 
Upvote 0
I didn't want to have to debug functions or catch type mismatches etc. I just wanted to know if there was some error, and if there was to echo out something like 0.
 
Upvote 0
I'm afraid I need a practical example. I rarely encounter errors in Access due to the stricter data typing (i.e., as compared to Excel).

ξ
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top