Help with simplifiy code

L

LDMueller

I can write a little vba code, but I'm not proficient enough to always write
it the most simpliest way. Can anyone help me simplify this code.

Private Sub cmdtest_Click()
If Me.cboQualityWorkProduct < 0.6 Then
Me.txtQualityWorkProduct = "0 - Not Observed"
Else
If Me.cboQualityWorkProduct > 0.5 And Me.cboQualityWorkProduct < 1.6 Then
Me.txtQualityWorkProduct = "1 - Does Not Meet SP Expectations"
Else
If Me.cboQualityWorkProduct > 1.5 And Me.cboQualityWorkProduct < 2.6 Then
Me.txtQualityWorkProduct = "2 - Does Not Meet SP Expectations"
Else
If Me.cboQualityWorkProduct > 2.5 And Me.cboQualityWorkProduct < 3.6 Then
Me.txtQualityWorkProduct = "3 - Meets SP Expectations"
Else
If Me.cboQualityWorkProduct > 3.5 And Me.cboQualityWorkProduct < 4.6 Then
Me.txtQualityWorkProduct = "4 - Meets SP Expectations"
Else
If Me.cboQualityWorkProduct > 4.5 And Me.cboQualityWorkProduct < 5.6 Then
Me.txtQualityWorkProduct = "5 - Meets SP Expectations"
Else
If Me.cboQualityWorkProduct > 5.5 And Me.cboQualityWorkProduct < 6.6 Then
Me.txtQualityWorkProduct = "6 - Exceeds SP Expectations"
Else
If Me.cboQualityWorkProduct > 6.5 And Me.cboQualityWorkProduct < 7.6 Then
Me.txtQualityWorkProduct = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboProductivity < 0.6 Then
Me.txtProductivity = "0 - Not Observed"
Else
If Me.cboProductivity > 0.5 And Me.cboProductivity < 1.6 Then
Me.txtProductivity = "1 - Does Not Meet SP Expectations"
Else
If Me.cboProductivity > 1.5 And Me.cboProductivity < 2.6 Then
Me.txtProductivity = "2 - Does Not Meet SP Expectations"
Else
If Me.cboProductivity > 2.5 And Me.cboProductivity < 3.6 Then
Me.txtProductivity = "3 - Meets SP Expectations"
Else
If Me.cboProductivity > 3.5 And Me.cboProductivity < 4.6 Then
Me.txtProductivity = "4 - Meets SP Expectations"
Else
If Me.cboProductivity > 4.5 And Me.cboProductivity < 5.6 Then
Me.txtProductivity = "5 - Meets SP Expectations"
Else
If Me.cboProductivity > 5.5 And Me.cboProductivity < 6.6 Then
Me.txtProductivity = "6 - Exceeds SP Expectations"
Else
If Me.cboProductivity > 6.5 And Me.cboProductivity < 7.6 Then
Me.txtProductivity = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboEfficiency < 0.6 Then
Me.txtEfficiency = "0 - Not Observed"
Else
If Me.cboEfficiency > 0.5 And Me.cboEfficiency < 1.6 Then
Me.txtEfficiency = "1 - Does Not Meet SP Expectations"
Else
If Me.cboEfficiency > 1.5 And Me.cboEfficiency < 2.6 Then
Me.txtEfficiency = "2 - Does Not Meet SP Expectations"
Else
If Me.cboEfficiency > 2.5 And Me.cboEfficiency < 3.6 Then
Me.txtEfficiency = "3 - Meets SP Expectations"
Else
If Me.cboEfficiency > 3.5 And Me.cboEfficiency < 4.6 Then
Me.txtEfficiency = "4 - Meets SP Expectations"
Else
If Me.cboEfficiency > 4.5 And Me.cboEfficiency < 5.6 Then
Me.txtEfficiency = "5 - Meets SP Expectations"
Else
If Me.cboEfficiency > 5.5 And Me.cboEfficiency < 6.6 Then
Me.txtEfficiency = "6 - Exceeds SP Expectations"
Else
If Me.cboEfficiency > 6.5 And Me.cboEfficiency < 7.6 Then
Me.txtEfficiency = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboInitiative < 0.6 Then
Me.txtInitiative = "0 - Not Observed"
Else
If Me.cboInitiative > 0.5 And Me.cboInitiative < 1.6 Then
Me.txtInitiative = "1 - Does Not Meet SP Expectations"
Else
If Me.cboInitiative > 1.5 And Me.cboInitiative < 2.6 Then
Me.txtInitiative = "2 - Does Not Meet SP Expectations"
Else
If Me.cboInitiative > 2.5 And Me.cboInitiative < 3.6 Then
Me.txtInitiative = "3 - Meets SP Expectations"
Else
If Me.cboInitiative > 3.5 And Me.cboInitiative < 4.6 Then
Me.txtInitiative = "4 - Meets SP Expectations"
Else
If Me.cboInitiative > 4.5 And Me.cboInitiative < 5.6 Then
Me.txtInitiative = "5 - Meets SP Expectations"
Else
If Me.cboInitiative > 5.5 And Me.cboInitiative < 6.6 Then
Me.txtInitiative = "6 - Exceeds SP Expectations"
Else
If Me.cboInitiative > 6.5 And Me.cboInitiative < 7.6 Then
Me.txtInitiative = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboDependability < 0.6 Then
Me.txtDependability = "0 - Not Observed"
Else
If Me.cboDependability > 0.5 And Me.cboDependability < 1.6 Then
Me.txtDependability = "1 - Does Not Meet SP Expectations"
Else
If Me.cboDependability > 1.5 And Me.cboDependability < 2.6 Then
Me.txtDependability = "2 - Does Not Meet SP Expectations"
Else
If Me.cboDependability > 2.5 And Me.cboDependability < 3.6 Then
Me.txtDependability = "3 - Meets SP Expectations"
Else
If Me.cboDependability > 3.5 And Me.cboDependability < 4.6 Then
Me.txtDependability = "4 - Meets SP Expectations"
Else
If Me.cboDependability > 4.5 And Me.cboDependability < 5.6 Then
Me.txtDependability = "5 - Meets SP Expectations"
Else
If Me.cboDependability > 5.5 And Me.cboDependability < 6.6 Then
Me.txtDependability = "6 - Exceeds SP Expectations"
Else
If Me.cboDependability > 6.5 And Me.cboDependability < 7.6 Then
Me.txtDependability = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If
If Me.cboCooperation < 0.6 Then
Me.txtCooperation = "0 - Not Observed"
Else
If Me.cboCooperation > 0.5 And Me.cboCooperation < 1.6 Then
Me.txtCooperation = "1 - Does Not Meet SP Expectations"
Else
If Me.cboCooperation > 1.5 And Me.cboCooperation < 2.6 Then
Me.txtCooperation = "2 - Does Not Meet SP Expectations"
Else
If Me.cboCooperation > 2.5 And Me.cboCooperation < 3.6 Then
Me.txtCooperation = "3 - Meets SP Expectations"
Else
If Me.cboCooperation > 3.5 And Me.cboCooperation < 4.6 Then
Me.txtCooperation = "4 - Meets SP Expectations"
Else
If Me.cboCooperation > 4.5 And Me.cboCooperation < 5.6 Then
Me.txtCooperation = "5 - Meets SP Expectations"
Else
If Me.cboCooperation > 5.5 And Me.cboCooperation < 6.6 Then
Me.txtCooperation = "6 - Exceeds SP Expectations"
Else
If Me.cboCooperation > 6.5 And Me.cboCooperation < 7.6 Then
Me.txtCooperation = "7 - Exceeds SP Expectations"
End If
End If
End If
End If
End If
End If
End If
End If

End Sub

Many thanks in advance!

LDMueller
 
D

Douglas J. Steele

Consider using the Select Case statement:

Select Case Me.cboQualityWorkProduct
Case Is < 0.6
Me.txtQualityWorkProduct = "0 - Not Observed"
Case 0.5 To 1.6
Me.txtQualityWorkProduct = "1 - Does Not Meet SP Expectations"
Case 1.5 To 2.6
Me.txtQualityWorkProduct = "2 - Does Not Meet SP Expectations"
Case 2.5 To 3.6
Me.txtQualityWorkProduct = "3 - Meets SP Expectations"
Case 3.5 To 4.6
Me.txtQualityWorkProduct = "4 - Meets SP Expectations"
Case 4.5 To 5.6
Me.txtQualityWorkProduct = "5 - Meets SP Expectations"
Case 5.5 To 6.6
Me.txtQualityWorkProduct = "6 - Exceeds SP Expectations"
Case 6.5 To 7.6
Me.txtQualityWorkProduct = "7 - Exceeds SP Expectations"
End Select

Note, though, that Case 0.5 To 1.6 equates to >= 0.5 and <= 1.6.

Note, too, that your original ranges were overlapping. While your combo box
may have had one decimal point values only, that doesn't mean that they'll
actually be treated as one decimal point values: 1.5 may actually be treated
as 1.5000001 (or 1.4999999)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top