VBE313
Well-known Member
- Joined
- Mar 22, 2019
- Messages
- 686
- Office Version
- 365
- Platform
- Windows
How can i better write this code and add error handling?
Code:
Function TotalStainless(EasyorHard As Double, Thickness As Double, NumOfPierces As Double, HoleCutLength As Double, TotalPerimeter As Double)
Dim PierceSecs As Double
Dim HolesInchPerMin As Double
Dim PerimInchPerMin As Double
Dim Efficiency As Double
Dim part1 As Double
Dim part2 As Double
Efficiency = Sheets("Standard").Range("AA4")
If Thickness = 0 Then
PierceSecs = 0.1
HolesInchPerMin = 280
PerimInchPerMin = 325
Else
If Thickness = 0.035 Then
PierceSecs = 0.2
HolesInchPerMin = 175
PerimInchPerMin = 200
Else
If Thickness = 0.048 Then
PierceSecs = 0.2
HolesInchPerMin = 175
PerimInchPerMin = 200
Else
If Thickness = 0.06 Then
PierceSecs = 0.3
HolesInchPerMin = 120
PerimInchPerMin = 140
Else
If Thickness = 0.075 Then
PierceSecs = 0.75
HolesInchPerMin = 100
PerimInchPerMin = 100
Else
If Thickness = 0.105 Then
PierceSecs = 0.75
HolesInchPerMin = 100
PerimInchPerMin = 100
Else
If Thickness = 0.135 Then
PierceSecs = 0.3
HolesInchPerMin = 70
PerimInchPerMin = 90
Else
If Thickness = 0.18 Then
PierceSecs = 0.3
HolesInchPerMin = 57
PerimInchPerMin = 65
Else
If Thickness = 0.25 Then
PierceSecs = 0.3
HolesInchPerMin = 57
PerimInchPerMin = 65
Else
If Thickness = 0.312 Then
PierceSecs = 1
HolesInchPerMin = 30
PerimInchPerMin = 35
Else
If Thickness = 0.375 Then
PierceSecs = 5
HolesInchPerMin = 25
PerimInchPerMin = 29
Else
If Thickness = 0.437 Then
PierceSecs = 4
HolesInchPerMin = 25
PerimInchPerMin = 29
Else
If Thickness = 0.5 Then
PierceSecs = 9
HolesInchPerMin = 15
PerimInchPerMin = 13
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If EasyorHard = 1 Then
part1 = (PierceSecs / Efficiency * NumOfPierces)
part2 = (HoleCutLength / HolesInchPerMin) / Efficiency + (TotalPerimeter / PerimInchPerMin) / Efficiency
Else
part1 = (PierceSecs / Efficiency * NumOfPierces) * (1 + Sheets("Standard").Range("J4"))
part2 = ((HoleCutLength / HolesInchPerMin) / Efficiency + (TotalPerimeter / PerimInchPerMin) / Efficiency) * (1 + Sheets("Standard").Range("J4"))
End If
part1 = Round(part1, 1)
part2 = Round(part2, 1)
TotalStainless = part1 + part2
End Function
Last edited by a moderator: