Hello Excel champions!
While the block of code below works however, it looks quiet an eye-sore as there are so many iterations that I believe can be simplified with nested loops. While I am currently fighting my intimidation to Looping statements, can you guys shed a light on me as to how this can be reduced into its simplest form? I will be going to study your solutions and hopefully get past my fear in looping.
Thanks in advance.
Private Sub CommandButton2_Click()
With Me
If .ComboBox1.Value = "" Then
MsgBox "Please select Tube Diameter and Thickness first", vbCritical
Exit Sub
ElseIf .TextBox1.Value <> "" And .TextBox2.Value = "" And .TextBox3.Value = "" And .TextBox4.Value = "" _
And .TextBox5.Value = "" And .TextBox6.Value = "" And .TextBox7.Value = "" And .TextBox8.Value = "" _
And .TextBox9.Value = "" And .TextBox10.Value = "" And .TextBox11.Value = "" And .TextBox12.Value = "" Then
Call str_tube_less_equal_90
GoTo Drawing
Exit Sub
ElseIf .TextBox1.Value <> "" And .TextBox2.Value <> "" And .TextBox3.Value = "" And .TextBox4.Value = "" _
And .TextBox5.Value = "" And .TextBox6.Value <= 90 And .TextBox7.Value = "" And .TextBox8.Value = "" _
And .TextBox9.Value = "" Then
If .TextBox12.Value <= 90 Or .TextBox12.Value = "" Then
Call sb_tube_less_equal_90
GoTo Drawing
Exit Sub
Else
GoTo Errmessage
Exit Sub
End If
ElseIf .TextBox1.Value <> "" And .TextBox2.Value <> "" And .TextBox3.Value <> "" And .TextBox4.Value = "" _
And .TextBox5.Value = "" And .TextBox6.Value <= 90 And .TextBox7.Value <= 90 And .TextBox8.Value = "" _
And .TextBox9.Value = "" Then
If .TextBox12.Value <= 90 Or .TextBox12.Value = "" Then
Call db_tube_less_equal_90
GoTo Drawing
Exit Sub
Else
GoTo Errmessage
Exit Sub
End If
ElseIf .TextBox1.Value <> "" And .TextBox2.Value <> "" And .TextBox3.Value <> "" And .TextBox4.Value <> "" _
And .TextBox5.Value = "" And .TextBox6.Value <= 90 And .TextBox7.Value <= 90 And .TextBox8.Value <= 90 _
And .TextBox9.Value = "" Then
If .TextBox12.Value <= 90 Or .TextBox12.Value = "" Then
Call tb_tube_less_equal_90
GoTo Drawing
Exit Sub
Else
GoTo Errmessage
Exit Sub
End If
ElseIf .TextBox1.Value <> "" And .TextBox2.Value <> "" And .TextBox3.Value <> "" And .TextBox4.Value <> "" _
And .TextBox5.Value <> "" And .TextBox6.Value <= 90 And .TextBox7.Value <= 90 And .TextBox8.Value <= 90 _
And .TextBox9.Value <= 90 Then
If .TextBox12.Value <= 90 Or .TextBox12.Value = "" Then
Call qb_tube_less_equal_90
GoTo Drawing
Exit Sub
Else
GoTo Errmessage
Exit Sub
End If
ElseIf .TextBox1.Value = "" And .TextBox2.Value = "" And .TextBox3.Value = "" And .TextBox4.Value = "" _
And .TextBox5.Value = "" And .TextBox6.Value = "" And .TextBox7.Value = "" And .TextBox8.Value = "" _
And .TextBox9.Value = "" And .TextBox10.Value <> "" And .TextBox11.Value <> "" And .TextBox12.Value <= 90 Then
Call sb_tube_less_equal_90
GoTo Drawing
Exit Sub
End If
Errmessage:
MsgBox "Error occurs due to any of the following instances:" & vbNewLine & vbNewLine & _
"- One of the angles indicated in upper section is greater than 90" & Chr(176) & vbNewLine & _
"- The angle indicated in lower section is greater than 90" & Chr(176) & vbNewLine & _
"- Required fields are left empty" & vbNewLine & _
"- Some text boxes are expecting inputs" & vbNewLine & vbNewLine & _
"Please go back and check your entries.", vbCritical, "Expecting inputs from required fields"
For i = 13 To 15
.Controls("TextBox" & i).Text = ""
Next i
Drawing:
For i = 0 To 8
If .Controls("TextBox" & i + 1).Text = "" Then
.Controls("Label" & i + 20).Caption = "L" & i + 1
If i + 20 >= 25 Then
.Controls("Label" & i + 20).Caption = Chr$(92 + i)
End If
Else
.Controls("Label" & i + 20).Caption = .Controls("TextBox" & i + 1).Text
End If
Next i
End With
End Sub
Bookmarks