Excel VBA Topic 2.4 - Message Boxes & Input Boxes

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

You would force them to put in the correct value by using a loop that only let's you leave the loop if you receive "acceptable" input.

davidschoenborn
Автор

How do you force the user to enter numerical values in the InputBox? If someone accidentally types a letter in, this will distort the result when using numerical operations.

jasminamrkonja
Автор

Hi, why it isn't necessary to dim variables num1, num2 and ans?
Wen shortening the macro to :
num1 = Range("B2")
num2 = Range("B3")
ans = num1 + num2


It request dimming the variables

edvirgiliom
Автор

I noticed that too.  If anyone know c++, we can do input validation but not sure how you would or could you do so in VBA.

erickwan
Автор

Not sure how to force users to do anything.  Fortunately, VBA continues on computing if a letter is used.  It merely assigns a "value" of zero to the entry.  Try it.  One way to alert them that they have made an error is to echo their inputs back to them using the message box, as Dr Nissenson's example does for the first value.  Simply add one more line of code to echo the second number, and your user has a better chance of discovering his/her mistake when the code is run.

ToddCoburn
Автор

Hey when i write the code (MsgBox num1&"+"&num2&"="&ans) in the last line of Sub inout(), it highlights the + sign and shows error Expected:End of statement. Please advise

adityabansal