vendredi 4 mars 2016

VBA If statement Issue

I'm using a userform with four text-boxes for users to enter numeric values that must amount (across the four inputs) to a total of 1.

I'm then using those values in conjunction with cell values to perform a calculation. In order to try and stop users from entering cumulative values of less than or greater than 1 I'm using the following If statement to be executed upon clicking the 'OK' button of the user form.

However, the Then Statement (display MsgBox and exit sub) even if the values to amount to 1. Whatever the values are, the If Statement is found to be true. Any ideas?

Private Sub OKButton_Click()
If DirectorBox.Value + SnrBox.Value + MngrBox.Value + ResearcherBox.Value <> 1 Then
    MsgBox "Values must amount to a total of 1"
    Exit Sub
End If
Sheets("Menu").Range("G13").Value = (Range("G9").Value * DirectorBox.Value) _
+ (Range("G10").Value * SnrBox.Value) + (Range("G11").Value * MngrBox.Value) _
+ (Range("G12").Value * ResearcherBox.Value)
Unload UserForm1
End Sub

Aucun commentaire:

Enregistrer un commentaire