Microsoft KB Archive/34748

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

Keywords : kbcode kbprg kbui
Version : 2.x 3.00 4.00 5.00 7.00 | 3.00 4
Platform : MACINTOSH OS/2 WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 7, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.