- Home
·
- Math/Dates
·
- Find average of 3 numbers with data validation and round answer to 2 decimal places.
Find average of 3 numbers with data validation and round answer to 2 decimal places.
Find average of 3 numbers with data validation and round answer to 2 decimal places.
Rate Find average of 3 numbers with data validation and round answer to 2 decimal places.
(2(2 Vote))
'label the label with the caption Average, remove all text from
'text boxes.
'enter the following code in the command button control.
Private Sub Command1_Click()
Const Count As Integer = 3
Dim FirstNum, SecondNum, ThirdNum As Integer
Dim Average, Sum As Currency
'validate data
If Text1 = vbNullString Or Text2 = vbNullString Or Text3 = vbNullString Then
MsgBox "No value entered, please make sure all entries are made", vbExclamation, "Missing Data"
End If
'validate data for numbers only
If Not IsNumeric(Text1) Or Not IsNumeric(Text2) Or Not IsNumeric(Text3) Then
MsgBox "Invalid entries, please enter numbers only", vbCritical, "Error"
End If
'find average of 3 numbers
FirstNum = Val(Text1)
SecondNum = Val(Text2)
ThirdNum = Val(Text3)
Sum = FirstNum + SecondNum + ThirdNum
Average = Sum / Count
Text4 = Round(Average, 2)
End Sub
Find average of 3 numbers with data validation and round answer to 2 decimal places. Comments
No comments yet — be the first to post one!
Post a Comment