Back

About MrExcel
Consulting Services
Learn Excel Resources
Challenge of the Month
MrExcel Seminars

Message Board

MrExcel Store
Podcast
Search
Contact
Home

 

 
David asks "Hi I have to design a project and i'm stuck on a bit which is designing a macro to allow the user to input a number, but the problem i'm facing is setting a validation which would only accept numbers between 1-10. I tried to set a validation on the specific cells but the problem with the inputbox is that even if the cell has been set to only accept a number it would accept anything. Can you please help because i can't really carry on with my project until this is done."

This macro will continue to ask the user for a number between 1 and 10 or will stop if he/she cancels.

Sub Test()
Dim MyAns As Variant

Ask:
MyAns = Application.InputBox("Enter a number between 1 and 10", Type:=1)
If MyAns = False Then Exit Sub
If MyAns < 1 Or MyAns > 10 Then GoTo Ask:
MsgBox MyAns, vbInformation, "Good Number"

End Sub

By Juan Pablo Gonzalez on 07-Feb-2002

MrExcel.com Consulting can be hired to implement this concept, or many other cool applications, with your data.

MrExcel.com provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures on this web site are provided "as is" and we do not guarantee that they can be used in all situations.

 

Excel is a registered trademark of the Microsoft® Corporation.

All contents Copyright 1998-2008 by MrExcel Consulting.