Microsoft Knowledge Base
Excel Macro to Prompt for Input and Insert on Worksheet
Last reviewed: July 7, 1997
Article ID: Q34748
The information in this article applies to:
- Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0
- Microsoft Excel for Windows 95, version 7.0
- Microsoft Excel for the Macintosh, versions 3.0, 4.0, 5.0
- Microsoft Excel for OS/2, versions 2.2, 2.21, and 3.0
SUMMARY
In Microsoft Excel, you can use the INPUT macro function to prompt for specific text input. This input can then be entered in a cell on a worksheet using the following example:
=FORMULA(INPUT("Enter Your Name",2),"SHEET1.XLS!r1c1")
When you run a macro that contains this command, you are prompted to enter your name in the input box, and the text that you enter is then inserted in cell A1 on SHEET1.XLS.
Note that when you use the RC notation, you must enclose the second parameter of the FORMULA function in quotation marks. When you use the A1 style notation, the quotation marks are not necessary.
Visual Basic Example
In Microsoft Excel versions 5.0 and 7.0, you can use the InputBox function in a Visual Basic procedure to accomplish this same task. The following Visual Basic example prompts you to enter your name, and then inserts the text you enter in cell A1 on Sheet1 in BOOK1.XLS:
Microsoft 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. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."
Workbooks("BOOK1.XLS").Worksheets("Sheet1").Range("A1").Formula = _ InputBox("Enter Your Name")
Additional query words: 2.00 2.01 2.10 2.21 2.20 3.00 4.00 5.00 7.00 Last reviewed: July 7, 1997 |