Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Error Catcher

Error Catcher

Error Catcher

Hey guys,

I've found an reeor in a program that i've been using, yet I'm struggling to fix it.  The code is given below.  The function essentially filters data within another sheet (containing ASME standard pipesizes) and gives the next size value of wall thickness.  

When a value for pipesize is entered that does not match any known values, it gives a random value for wall thickness.

The rest of the code works perfect, but I need a line of code to catch this error, yet I'm still not great with VBA so everything I do gives me an error...

Cheers guys

Function findASMEwallthickness(pipesize, selectedwt)
Dim ws As Worksheet
Dim FilterRange As Range
Dim i%, m
Set ws = Sheets("ASME B36.10M-2004 Pipe Size")

'Autofilter ASME sheet based on pipesize required
ws.Range(ws.Range("A1:J1"), ws.Range("A1:J1").End(xlDown)).AutoFilter Field:=1, Criteria1:=pipesize

'Set the lookup range to only column I, and visible cells (filtered cells)
Set FilterRange = ws.Range("I2:I" & Rows.Count).SpecialCells(xlCellTypeVisible)
'Locate closest match to require wall thickness in specified range (greater than value)
With FilterRange
i = .Row
m = Application.Match(selectedwt, .Value, 1)

'Error catcher
If Not IsError(m) Then i = .Cells(1, 1).Offset(m).Row
End With
'If pipe is >8", use two sizes above specified WT, else use only only next size up
If selectedwt > 8 Then
    findASMEwallthickness = (ws.Cells(i + 1, 9).Value)
    'MsgBox (ws.Cells(i + 1, 9).Value)
    findASMEwallthickness = (ws.Cells(i, 9).Value)
    'MsgBox (ws.Cells(i, 9).Value)
End If
'Remove filter mask

End Function

RE: Error Catcher

Cheers, I'll get on that.  

Sorry, still getting used to the forums

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close