Not sure what tbox2 is, but assuming it's a range name, then you should first BE in tbox2, enter:
=IF(tb1=2,28,if(tb1=or({4,6,9,11}),30,31))
30 Days has September,,,,
I assume these are text boxs on a form so here is the code on the form:
Private Sub TextBox1_Change()
numberIn = TextBox1.Text
Select Case numberIn
Case 2
TextBox2.Text = 28
Case 4, 6, 9, 11
TextBox2.Text = 30
Case Else
TextBox2.Text = 31
End Select
End Sub
Good Luck
Re: 30 Days has September,,,,I wrote code for it and it worked, your's much shorter!!! Thanks
Here is the code with checks that the number entered is between 1 and 12:
Private Sub TextBox1_Change()
numberIn = TextBox1.Text
If numberIn = "" Then
TextBox2.Text = ""
Exit Sub
End If
If IsNumeric(numberIn) Then
If numberIn > 0 And numberIn < 13 Then
Select Case numberIn
Case 2
TextBox2.Text = 28
Case 4, 6, 9, 11
TextBox2.Text = 30
Case Else
TextBox2.Text = 31
End Select
Else
TextBox1.Text = ""
str1 = "Must enter a value between 1 and 12"
i = MsgBox(str1, vbExclamation + vbOKOnly, "Please enter a number")
End If
Else
TextBox1.Text = ""
str1 = "Must enter a value between 1 and 12"
i = MsgBox(str1, vbExclamation + vbOKOnly, "Please enter a number")
End If
End Sub
This is a lot better, would you not agree? : I assume these are text boxs on a form so here is the code on the form
Does not February have 29 every 4 years AND every century? (NT)