Input Box

Abvlecxe

Board Regular
Joined
Sep 10, 2015
Messages
53
Hi looking for help with my input box macro below, I am looking to have the macro only allow certain numbers e.g. 10,20,30,40,50 etc but this doesn't work:

Sub runQsheet()
Dim myValue As Variant
Do
myValue = InputBox("Enter Fiscal Week Number", "Report Refresh", 1)
'cancel pressed
If StrPtr(myValue) = 0 Then Exit Sub
'inform user
If Not IsNumeric(myValue) Then MsgBox "Numeric Values Only" & Chr(10) & _
"Multiples of 10"
Loop Until Val(myValue) = 10,20,30,40,50

Range("B1").Value = CLng(myValue)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You don't need a macro to limit entry into cell B1. You can use data validation. Select cell B1 and in Data Validation, select "Custom" in the 'Allow' box and in the 'Formula' box, enter this formula: =MOD(B1,10)=0
 
Last edited:
Upvote 0
Hi thanks for response.

The input result i am actually using for another peace of code but i need to restrict the user selection to multiples of 10, do you know the code for this?

I have since googled and have found that if i put in
Loop Until Val(myValue) = 10 or my value = 20 or my value = 30
But the range i have goes up to 500 so this can't be the most efficient way to do this

Thanks







You don't need a macro to limit entry into cell B1. You can use data validation. Select cell B1 and in Data Validation, select "Custom" in the 'Allow' box and in the 'Formula' box, enter this formula: =MOD(B1,10)=0
 
Upvote 0
Following on from mumps' suggestion, you could use:
=OR(B1<=500,MOD(B1,10)=0)
 
Last edited:
Upvote 0
If you are saying that you want to validate the input in the range B1:B500, select that range and use this formula: =AND(B1<=500,MOD(B1,10)=0) (slighty modified from craigexcel's suggestion)
 
Upvote 0
Thanks for seeing that correction to be made. Definitely AND, not OR. :-)
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top