Error Catcher
Error Catcher
(OP)
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
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
RE: Error Catcher
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
Chinese prisoner wins Nobel Peace Prize
RE: Error Catcher
Sorry, still getting used to the forums
RE: Error Catcher