This is probably a really basic question, but what is the most efficient way to restructure this code to eliminate all of the if-thens? I'm thinking "With" but it did not work when I tried. This is part of a dynamic userform that automatically calculates required cycle times based on production data and efficiencies. It works, but man is it some ugly coding.
Updating any unlocked text box in the form calls the "Update" sub. All it does is check to make sure everything is filled out prior to recalculating.
Updating any unlocked text box in the form calls the "Update" sub. All it does is check to make sure everything is filled out prior to recalculating.
Code:
Private Sub Update()
If Trim(weeks.Value & vbNullString) <> vbNullString Then
If Trim(days.Value & vbNullString) <> vbNullString Then
If Trim(shifts.Value & vbNullString) <> vbNullString Then
If Trim(hours.Value & vbNullString) <> vbNullString Then
If Trim(volume.Value & vbNullString) <> vbNullString Then
If IsNumeric(weeks.Value) = True Then
If IsNumeric(days.Value) = True Then
If IsNumeric(shifts.Value) = True Then
If IsNumeric(hours.Value) = True Then
If IsNumeric(volume.Value) = True Then
VPW.Value = Round(volume.Value / weeks.Value, 1)
VPD.Value = Round(VPW.Value / days.Value, 1)
VPS.Value = Round(VPD.Value / shifts.Value, 1)
VPH.Value = Round(VPS.Value / hours.Value, 1)
E100.Value = (3600 / volume.Value) * weeks.Value * days.Value * shifts.Value * hours.Value
E95.Value = E100.Value * 0.95
E90.Value = E100.Value * 0.9
E85.Value = E100.Value * 0.85
E80.Value = E100.Value * 0.8
E75.Value = E100.Value * 0.75
If ECustomInput.Value = "" Then
ECustom.Value = 0
Else
ECustom.Value = E100.Value * (ECustomInput.Value / 100)
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
Last edited: