Microsoft KB Archive/188565

= XL98: Using the RefEdit Control with a UserForm =

Article ID: 188565

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q188565





SUMMARY
In Microsoft Excel, there is no Help topic for the RefEdit control. This article describes the RefEdit control and provides information about using the RefEdit control in a UserForm.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. A RefEdit control is similar in behavior and appearance to an edit box control with an InputType property that you set to xlReference. (The edit box control is available in Microsoft Excel 5.0 on the Forms toolbar in dialog sheets.) The RefEdit control differs from an edit box control in that the RefEdit control contains a button that allows you to collapse the UserForm to easily select a cell range.

Using an Edit Box
The RefEdit control imitates the behavior of the reference edit boxes that are built into Microsoft Excel. To illustrate how the built-in reference edit boxes work in Microsoft Excel, follow these steps:
 * 1) In a new worksheet, click Function on the Insert menu to display the Function Wizard.
 * 2) Click SUM in the Function Name box and click OK.

Notice that the edit box for the first argument contains a button with a red arrow on the right side.
 * 1) Click the button with the red arrow in the edit box.

The Function Wizard collapses, which allows you to see more of your worksheet.
 * 1) Drag the pointer over cells in the worksheet.

The reference for the cells appears in the reference edit box.
 * 1) Click the button in the edit box to expand the Function Wizard.
 * 2) Click OK or Cancel.

Using the RefEdit Control on a UserForm
The following example illustrates how to create a UserForm that contains a RefEdit control and a CommandButton control. When the UserForm appears, you enter a reference in the RefEdit control and click OK. When you click OK, the range that you referenced is formatted with a red background, and the UserForm is unloaded. To illustrate how the RefEdit control works in Microsoft Excel, follow these steps:  In a new workbook, press OPTION+F11 to activate the Visual Basic Editor. On the Insert menu, click UserForm.

This step inserts UserForm1 into your project. If the Toolbox is not displayed, click Toolbox on the View menu. In the Toolbox dialog box, click RefEdit, and draw the control on UserForm1.

To determine which button is the RefEdit button, move the pointer over the button and examine the name that appears in the ToolTip. In the Toolbox dialog box, click CommandButton and draw the CommandButton on UserForm1. With the CommandButton selected, press F6 to display the Properties window. Change the Caption property of the control to OK. Double-click the CommandButton to open the Code window for the CommandButton.</li>  Type the following code for the Click event of the CommandButton: Sub CommandButton1_Click

Dim SelRange as Range Dim Addr as String

'Get the address, or reference, from the RefEdit control. Addr = RefEdit1.Value

'Set the SelRange Range object to the range specified in the 'RefEdit control. Set SelRange = Range(Addr)

'Apply a red pattern to the SelRange. SelRange.Interior.ColorIndex = 3

'Unload the userform. Unload Me

End Sub </li> Click Module on the Insert menu to insert a Visual Basic module sheet.</li>  Type the following code into the module sheet: Sub ShowForm

UserForm1.Show

End Sub </li> On the File menu, click "Close and Return to Microsoft Excel."</li> Point to Macro on the Tools menu, and then click Macros, Click ShowForm, and then click Run.

The UserForm is displayed.</li> Click the button in the RefEdit control. Notice that the UserForm collapses. Select a range of cells on the worksheet, and then click the RefEdit button to expand the UserForm.</li> Click OK.</li></ol>

The UserForm disappears, and the cells that you selected are formatted with a red background.

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

163435 VBA: Programming Resources for Visual Basic for Applications

Additional query words: 8.00 Ref Edit user form

Keywords: kbdtacode kbhowto kbprogramming KB188565

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.