Excel: Code Problem: Empty Text Box


Hi, I am fairly new to VBA, so this might be rather trivial. I have a Userform with a Text Box to enter a number. I want to check, if there was a number entered in the Text Box. If a number was entered, a certain calculation is to be done with that number If no number was entered, then this Text Box is rated with a certain grade (e.g. 10) and further calculation is to be done with that grade. I have written the code below: [I]Dim A As Variant[/I] [I]Dim B As Variant[/I] [I] Private Sub btnCheck_Click()[/I] [I]If txtA.Text = "" Then[/I] [I] Msg = "You have entered no value for A. Do you want to continue?"[/I] [I] Ans = MsgBox(Msg, vbYesNo)[/I] [I] If Ans = vbNo Then Exit Sub[/I] [I] If Ans = vbYes Then txtA.Text = “#N/A”[/I] [I]End If[/I] [I]A = txtA.Text[/I] [I]If A = “#N/A” Then B = 10[/I] [I]If A > 0 And A <= 400 Then B = 0[/I] [I]If A > 400 Then B = (A - 400) * 0.1[/I] The above does not work. If I exchange "#N/A" with a number, such as "0", then everything works fine. However, this is not what I want. How do I assign an 'empty' Text Box to a variable? Thanks, H.


This question generated 15 answers. To proceed to the answers, click here.

This thread is current as of December 16, 2014.


For more resources for Microsoft Excel