Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Catcher

Status
Not open for further replies.

maloneb

Mechanical
Aug 11, 2011
22
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)
Else

findASMEwallthickness = (ws.Cells(i, 9).Value)
'MsgBox (ws.Cells(i, 9).Value)

End If

'Remove filter mask
ws.ShowAllData

End Function
 
Replies continue below

Recommended for you

Cheers, I'll get on that.

Sorry, still getting used to the forums
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor