How to handle #error when testing cell with Len() function

tinkythomas

Active Member
Joined
Dec 13, 2006
Messages
432
Hi,

How can I handle cells that could contain #REF, #N/A etc when testing cell value for length?

I get runtime error 13 (type mismatch) when a cell contains an #error as a result of a formula. I'm using a statement in vba like the following...

If Len(Cells(1, 1)) = 0 Then Do Something

Regards,
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You can test the cell for an error using the following (or its iferror - not sure as on my phone)

Application.WorksheetFunctions.IsError()

D
 
Upvote 0
Hi,

Thanks for the reply. Sorry should have mentioned that I had already tried that with...

If Len(Cells(1, 1)) = 0 Or WorksheetFunction.IsError(Cells(1, 1)) Then Do Something

but it still get the runtime error 13.

Thanks,
 
Upvote 0
I would try the IsError first, then check the length as a second if statement.

Otherwise we can create a range variable, set it to the cell in question, and test if that's not null.

Or skip errors altogether with, On error resume next

D
 
Upvote 0
Thanks for your help. Putting the IsError first worked with the Len() check as an ElseIf. Would it be possible to use the single line form with an ElseIf? I tried it but couldn't get it to work, it just wouldn't compile.

The single line form works with just 1 condition but not with an ElseIf???

Thanks,
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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