Restrict inputbox to rounded numeric values

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Restrict inputbox to rounded numeric values

Post by MSingh »

Hi Hans,

I need to restrict user input into an input box to rounded numeric values only.

My code so far:

Sub Limit2()
Dim strMsg As String
strMsg = Application.InputBox("Enter Export Limit" & _
" Rand Value")
If strMsg <> "" Then Sheets("SheetName").Range("AF11").Value = strMsg
End Sub

Please advise.

Thanking you
Mohamed

Ps. I keep posting a new question as a "reply". Should i be posting these differently?

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Restrict inputbox to rounded numeric values

Post by HansV »

I have moved your question to a thread of its own because it is about a different subject than the thread Hide name box and activate first page of multipage control in which you posted it.

If you have a question that directly follows from an already existing thread, you should post it as a question in that thread. But if you have a new question about an unrelated subject, it's best to start a new thread by clicking the NEWTOPIC button in the forum.

If you want the user to enter a whole number, you can use

Dim lngInput As Long
lngInput = Application.InputBox(Prompt:="Enter Export Value", Type:=1)

Type:=1 specifies that the user can only enter a number; text values will be rejected. See InputBox Method.

If you want the user to enter a number and round it to (for example) 2 decimal places, you can use

Dim dblInput As Double
dblInput = Round(Application.InputBox(Prompt:="Enter Export Value", Type:=1), 2)
Best wishes,
Hans

MSingh
3StarLounger
Posts: 366
Joined: 12 May 2010, 06:49

Re: Restrict inputbox to rounded numeric values

Post by MSingh »

Thanks Hans,

That solves both my questions.

Kind Regards
Mohamed