ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Decide what an INPUTBOX is supposed to return

If you want to get any information from the user you can use the INPUTBOX-function. This function displays a dialogbox that lets the user fill inn anything and returns the content as a string.

Sometimes you want to decide what the user is supposed to fill in, instead of accepting any information. That's when you use the INPUTBOX-method :

Sub DecideUserInput()
Dim bText As String, bNumber As Integer
    ' here is the INPUTBOX-function :
    bText = InputBox("Insert in a text", "This accepts any input")
    ' here is the INPUTBOX-method :
    bNumber = Application.InputBox("Insert a number", "This accepts numbers only", , , , , , 1)
    MsgBox "You have inserted :" & Chr(13) & _
        bText & Chr(13) & bNumber, , "Result from INPUT-boxes"
End Sub

The INPUTBOX-method has a third argument, Type, that decides what the user is allowd to insert in the INPUTBOX-dialog. Type can be one of the following :

Type :

Accepted input:

0

A formula

1

A number

2

Text

4

A logical value (True or False)

8

A cell reference, e.g. a Range-object

16

An error value, e.g. #N/A

64

An array of values

 

Document last updated 2000-02-05 12:47:20      Printerfriendly version

User comments:
Ole P. from Norway wrote (2006-08-29 22:01:57 CET):
Re: inputbox
No, the InputBox does not have this feature.
You will have to create your own UserForm and add a RefEdit control that will allow the user to select a cell range from the worksheet.
Wisnu Naumowicz Kusumoaji from Jakarta, Indonesia wrote (2006-08-29 21:00:29 CET):
inputbox
if the user want to select range directly from the worksheet,is the input box methode have the ability to do that?

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2024    Ole P. Erlandsen   All rights reserved
E-mail Contact Address