VBA Error in a Function

maloneb

New Member
Joined
Aug 1, 2011
Messages
20
Hey Guys,

I'm having an issue with a function that I am using. Basically, the input change the outputs (as would be expected...), and two of the calculated outputs are used in the function, findASMEwallthickness.

This function filters the values in the second sheet (ASME B36. 10m-2004 Pipe Size) in accordance with the appropriate pipesize and uses the next wall thickness up from the calculated minimum wall thickness. In theory.

The function works fine for any pipe diameter over 350mm, yet if the pipe diameter is equal to or less than 350mm, the function gives out wron answers.

A link to the workbook is given below, thanks.

B

http://files.engineering.com/getfil...a-4b27-a727-b15dd912b566&file=PD8010_Test.xls
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Oh man, sorry! I didn't know how to do it so used Engineering-Tips to upload it. How do you use excel Geenie?

Sorry!
 
Upvote 0
Here is the VBA code, I don't know how to upload the workbook.

Thanks


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
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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