Printer Friendly
The Free Library
14,581,301 articles and books
Member login
User name  
Password 
 
Join us Forgot password?

Spreadsheets with something extra: how to add explanatory messages and input boxes to your cells.


Have you ever created a spreadsheet spreadsheet

Computer software that allows the user to enter columns and rows of numbers in a ledgerlike format. Any cell of the ledger may contain either data or a formula that describes the value that should be inserted therein based on the values in other cells.
 only to open it a couple of months later to discover you couldn't remember how to update it or what data it needed? Or, if you prepared the spreadsheet for others in your organization, did they keep calling you for instructions on how to use it?

You can eliminate those problems and, as a by-product by·prod·uct or by-prod·uct  
n.
1. Something produced in the making of something else.

2. A secondary result; a side effect.


by-product
Noun

1.
, ensure the accuracy of spreadsheets by enhancing them with easy-to-create graphic messages and input boxes that can provide reminders, explain various functions of the data tables, help users find and enter the right data and even refuse to let them proceed unless they follow a prescribed pre·scribe  
v. pre·scribed, pre·scrib·ing, pre·scribes

v.tr.
1. To set down as a rule or guide; enjoin. See Synonyms at dictate.

2. To order the use of (a medicine or other treatment).
 procedure. In short, those boxes serve as automated au·to·mate  
v. au·to·mat·ed, au·to·mat·ing, au·to·mates

v.tr.
1. To convert to automatic operation: automate a factory.

2.
 stand-ins for the spreadsheet creator, who can design them to appear whenever a user opens the spreadsheet. Though you have to write message and input boxes in the Visual Basic for Applications (VBA (Visual Basic for Applications) A subset of Visual Basic that provides a common language for customizing Microsoft applications. VBA supports COM, which allows a VBA script to invoke internal functions within Excel, Word and other COM-based programs or to make use of ) language, which is built into Microsoft Excel (tool) Microsoft Excel - A spreadsheet program from Microsoft, part of their Microsoft Office suite of productivity tools for Microsoft Windows and Macintosh. Excel is probably the most widely used spreadsheet in the world.

Latest version: Excel 97, as of 1997-01-14.
, you will be happy to know it is easy to learn.

GET THE MESSAGE

Let's begin by creating a message box. The message may be a greeting to the user, instruction about using the spreadsheet or a reminder to complete a task. The message syntax syntax: see grammar.
syntax

Arrangement of words in sentences, clauses, and phrases, and the study of the formation of sentences and the relationship of their component parts.
, in its simplest form, is: MsgBox "prompt", where the words between the quote marks are the message.

To make a message box, open Excel and press Alt+F11 to launch the Visual Basic Editor. Another way to start the editor is to click on Tools, Macro and then select Visual Basic Editor. Once it begins, click on Insert, then Module to open a VBA screen; that's the place where you will write the VBA code, which is technically called the subroutine A group of instructions that perform a specific task. A large subroutine might be called a "module" or "procedure." Subroutine is somewhat of a dated term, but it is still quite valid.  or subprocedure.

All subroutines must start with the word Sub and finish with End Sub. After typing Sub, give the routine a name followed by open and closed parentheses See parenthesis.

parentheses - See left parenthesis, right parenthesis.
. As a practical matter, the name you assign should describe your routine so it will be easy to identify.

A subroutine for a welcoming message box, called Hello, would look like this:

Sub Hello ()

MsgBox "Hello!!"

End Sub

Exhibit 1, page 53, shows a sample of such a message box and the code that produced it. After users read the message box and press the OK button, it disappears from the screen.

[ILUSTRATION OMITTED]

You can change the type of button and icon appearing in the message box by adding code numbers after the message. Exhibits 2 and 3 (page 53) show the various codes for each.

For example, if you want the message box to show the OK and Cancel buttons and the Information message icon, add the total values associated with them--in this case it is 65 (1 + 64)--and enter that number after the message preceded by a comma. Exhibit 4, below, shows the code and the resulting message box.

[ILLUSTRATION OMITTED]

To change the self-promoting Microsoft Excel default title of the message box from appearing in the upper left-hand corner, type in your choice, in quotes, immediately after the comma and after your button/icon number. Exhibit 5, page 54, shows you the code and the resulting message box where the title has been changed to Greetings from Accounting.

[ILLUSTRATION OMITTED]

Exhibit 6, page 54, shows a different form of message box containing Yes and No buttons along with a critical message icon. Later in the article we'll describe how to use this type of message box, which invites a response from users and will not let them proceed until they answer the question.

[ILLUSTRATION OMITTED]

A message box allows you to display a message of up to 1,024 characters--so you have plenty of room for informative text. If you want to use multiple lines in your message box, add & Chr(13) & at the points you want a line break. Exhibit 7, page 54, is an example of a message box with line breaks.

[ILLUSTRATION OMITTED]

A message box also can retrieve information from your Excel spreadsheet and include it as part of your message. The information can be added before, inside or after any part of your message. The code for retrieving the information from Excel is & Range("cell location").Value &. Exhibit 8, page 54, shows a message where the person's name is retrieved from cells A1 and B1.

[ILLUSTRATION OMITTED]

Now that you know how to write a basic message box, let's add additional VBA code that will send a user to different places in your worksheet depending on the button pushed. We'll use the message box developed in exhibit 6 to demonstrate a routine in which, if the user pushes the Yes button, the cursor (1) The symbol used to point to some element on screen. On Windows, Mac and other graphics-based screens, it is also called a "pointer," and it changes shape as it is moved with the mouse into different areas of the application.  will move to sheet 3, cell A1 of the workbook work·book  
n.
1. A booklet containing problems and exercises that a student may work directly on the pages.

2. A manual containing operating instructions, as for an appliance or machine.

3.
; and if the user pushes No, the cursor moves to A1 of the current worksheet. For that, you will need additional buttons; the standard ones are listed in exhibit 9, page 54.

For the Yes button the code is 6; for No the code is 7. A temporary variable now needs to be added to the routine to store this information. We will call this temporary variable returnvalue--although you may use any name--and add it before the word MsgBox followed by an equal sign. In this case, because the routine is required to return data, the MsgBox function is surrounded by parentheses rather than quote marks.

To implement the Yes, No function, we will use an If ... Then ... Else statement. As exhibit 10, page 54, shows, the If ... Then ... Else statement is written to test the user's choice. If the temporary variable returnvalue equals 6, the user will be taken to sheet 3, cell A1 of the workbook, and if returnvalue does not equal to 6, the user will be sent to A1 of the current worksheet.

[ILLUSTRATION OMITTED]

PROMPTING A PROMPT

At times you may want to capture written information from the user or remind yourself to leave a written message in your worksheet. Do this with an input box. The InputBox function displays a prompt in a dialog box A movable window that is displayed on screen in response to the user selecting a menu option. It provides the current status and available options for a particular feature in the program.  and waits for the user to input text. The prompt tells the user what kind of input is requested (for example, the name of the recipient). The properties of an InputBox are similar to that of the MsgBox; the prompt can be 1,024 characters long and lengthy prompts can be separated into multiple lines by using the carriage return character--& Chr(13) &.

The standard code of the InputBox function is InputBox ("prompt","title"), where prompt refers to the message written in the input box and title refers to the title in the upper left-hand corner. If you want the information inserted by the user to automatically return to your worksheet, specify the target for this information. Exhibit 11, page 55, shows an input box that captures the user's name and places it in cell B5 of a worksheet named Cost.

[ILLUSTRATION OMITTED]

Now that you see how simple message and input boxes are to incorporate into your spreadsheet, you will discover you can do many handy things with them--including a combination of routines. For instance, assume you want to put a control in your worksheet that forbids the user to leave an input box blank. If the user fails to enter data in that cell, a pop-up message is triggered and the user is not allowed to proceed until he or she puts the information in. Doing this requires the use of the If ... Then ... Else statement with a message box and also a Do ... Loop. An example is shown in exhibit 12, at right.

[ILLUSTRATION OMITTED]

You can program Excel to evoke e·voke  
tr.v. e·voked, e·vok·ing, e·vokes
1. To summon or call forth: actions that evoked our mistrust.

2.
 a message and input box when a workbook or worksheet opens or closes or when a user clicks on a button. To automatically have a message box appear when your workbook is opened, do the following, as shown in exhibit 13, below:

1. Enter the Visual Basic Editor (Alt+F11) and click on This Workbook in the VBA Project Explorer window.

2. From the View menu, select Code and a code window will open to allow you to type in code specifically for the workbook.

3. From within this code window, select Workbook from the drop-down menu See pull-down menu.

drop-down menu - pull-down menu
 on the left and Open from the drop-down menu on the right. That will create a subroutine, which will run automatically when a user opens your workbook.

4. Finally, inside this subroutine, type in the message or input box function that you want.

[ILLUSTRATION OMITTED]

To have another subroutine created that runs when the workbook is closed, select the BeforeClose action from the drop-down on the right. Then you can type in your new code.

If you want to evoke a message box when a user enters or exits a worksheet, follow these steps, as shown in exhibit 14, page 56:

[ILLUSTRATION OMITTED]

1. Enter the Visual Basic Editor and click on the worksheet to be activated activated

a state of being more than usually active. In biological systems this is usually brought about by chemical or electrical means. Commonly said of pharmaceutical and chemical products.
 in the VBA Project Explorer window.

2. From the View menu, select Code and a code window will open to allow you to type in code specifically for the selected worksheet.

3. Within this window, if you select Worksheet from the drop-down menu on the left and Activate (1) See trigger.

(2) To interact with an activation server at the time copy-protected software is installed. The install program generates a code that is sent to the activation server, which responds with an authorization code that allows the software to operate.
 from the drop-down on the right, a subroutine will be created that will run automatically upon entering your worksheet.

4. Finally, inside this subroutine, you can type the message or input box function you want.

To have another subroutine created that runs when the worksheet is exited, select the Deactivate de·ac·ti·vate  
tr.v. de·ac·ti·vat·ed, de·ac·ti·vat·ing, de·ac·ti·vates
1. To render inactive or ineffective.

2. To inhibit, block, or disrupt the action of (an enzyme or other biological agent).

3.
 action from the drop-down menu on the right. Then you can type in your code.

If you want the message box to appear only when a user asks for it, click on View, Toolbars, Forms. That brings up the Forms toolbar A row or column of on-screen buttons used to activate functions in the application. Many toolbars are customizable, letting you add and delete buttons as required. Toolbars may be fixed in position or may float, which means they can be dragged to a more convenient location in the  (exhibit 15, at left). Center your mouse over the button, as shown in the exhibit, left-click on it and then release it. Now move your cursor where you want the button. Note how your cursor becomes a thin cross when you move it around the spreadsheet. Once you place the button, left-click your mouse, holding it down as you adjust its size.

[ILLUSTRATION OMITTED]

When finished, release the button and an Assign Macro dialog box will appear, as shown in exhibit 16, at left. Simply click on the macro you wrote and click on OK. Your macro is now assigned to your button. When a user clicks on it, the Hello message box will appear.

[ILLUSTRATION OMITTED]

If the Assign Macro dialog box doesn't appear or you want to assign a new macro to your button, right-click when the cursor is over the button and a shortcut (1) In Windows, a shortcut is an icon that points to a program or data file. Shortcuts can be placed on the desktop or stored in other folders, and double clicking a shortcut is the same as double clicking the original file.  menu will pop up. Choose the Assign Macro selection, evoking the same dialog box. If you want a picture for your button, right-click while the cursor is on the picture and the same menu will appear. Again, choose Assign Macro.

Now that you know the fundamentals of creating message and input boxes, you're sure to come up with many ways of your own to use them and make your spreadsheets much more valuable, useful and friendly. And it takes just a small investment of time.
Exhibit 2

Value   Button

0       OK
1       OK and Cancel
2       Abort, Retry and Ignore
3       Yes, No and Cancel
4       Yes and No
5       Retry and Cancel

Exhibit 3

Value   Description                Icon

16      Critical message icon        x
32      Warning query icon           ?
48      Warning message icon         !
64      Information message icon     i
0       Blank                      Blank

Exhibit 9

Button-return   Button
value           clicked

1               OK
2               Cancel
3               Abort
4               Retry
5               Ignore
6               Yes
7               No


Key to Instructions

To help readers follow the instructions in this article, we use two different typefaces This is a list of typefaces. Serif
Here you can find a graphical version of this table.
  • Aldus
  • Antiqua
  • Aster
  • Baskerville
  • Bell (Monotype) Didone classification serif type deisgned by Richard Austin, 1788
  • Bembo
  • Benguiat
.

Boldface See boldface font.  type identifies the names of icons, agendas, URLs and application commands.

Sans serif Short horizontal lines added to the tops and bottoms of traditional typefaces, such as Times Roman. Contrast with sans-serif.

 type indicates instructions and commands that users should type and file names.

LOIS LOIS Land-Ocean Interaction Study
LOIS Law Office Information Systems
LOIS Lofar Outrigger in Scandinavia
LOIS Loss of Interim Status
LOIS Laser Operated Ion Source
LOIS Learning Options in Suffolk
LOIS Location Oriented Information System
 S. MAHONEY, CPA (Computer Press Association, Landing, NJ) An earlier membership organization founded in 1983 that promoted excellence in computer journalism. Its annual awards honored outstanding examples in print, broadcast and electronic media. The CPA disbanded in 2000. , PhD, CMA CMA - Concert Multithread Architecture from DEC. , is an assistant professor at the University of Central Florida's School of Accounting. Her e-mail address See Internet address.

e-mail address - electronic mail address
 is lois.mahoney@bus.ucf. edu. JUDITH K. WELCH Welch , William Henry 1850-1934.

American pathologist and bacteriologist who discovered the bacteria that causes gas gangrene.
, CPA, PhD, is an associate professor at the University of Central Florida's School of Accounting. Her e-mail address is judith.welch@bus.ucf.edu.
COPYRIGHT 2003 American Institute of CPA's
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 2003, Gale Group. All rights reserved. Gale Group is a Thomson Corporation Company.

 Reader Opinion

Title:

Comment:



 

Article Details
Printer friendly Cite/link Email Feedback
Title Annotation:Microsoft Excel
Author:Welch, Judith K.
Publication:Journal of Accountancy
Date:Feb 1, 2003
Words:2025
Previous Article:Period of adjustment: CPAs are finding ways to put auditing and consulting on different sides of the conflict-of-interest dividing line.
Next Article:Standing up for what we stand for: the Institute's new chairman urges CPAs to live by their core values.(American Institute of Certified Public...
Topics:



Related Articles
The mighty mouse: enhancing spreadsheet productivity. (for accounting)
The power of spreadsheets. (software programs)
Add perspective to spreadsheets.(information analysis by CPAs using spreadsheet software)
In Excel, cell names spell speed, safety: give a cell a name, and your work will go faster and be more error-free.
Boost profits with Excel: Solver calculates the most cost-effective and profitable product mix.
Collaborate on spreadsheets: how to share Excel files with others on your network.
Ferret out spreadsheet errors: use Excel's tools to uncover and correct formula problems.
Add even more muscle to "what-if" analyses: team Scenario Manager with Scenario PivotTable for a more powerful tool.(part 2)
Double-teaming in Excel: spreadsheets now can solve tougher calculations.
Navigate speedily in excel data: click on a button to get to target information.

Terms of use | Copyright © 2009 Farlex, Inc. | Feedback | For webmasters | Submit articles