Microsoft KB Archive/213224

= XL2000: Visual Basic Example for Using a Spin Button with a Date =

Article ID: 213224

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213224





SUMMARY
In Microsoft Excel 2000, you can use a SpinButton control on a UserForm to change values on a worksheet or in a Visual Basic procedure. Microsoft Visual Basic for Applications in Excel 2000 provides the ability to attach procedures to object events such as clicking on the DOWN ARROW of the spin button (SpinDown event) and clicking on the UP ARROW (SpinUp event).



MORE INFORMATION
Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

To use a SpinButton control to both increment and decrement a date value in an edit box, follow these steps:  From a new workbook in Microsoft Excel 2000, press ALT + F11 to start the Visual Basic Editor. In the Microsoft Visual Basic Editor, click Insert, and then select UserForm. Click the TextBox tool in the Controls Toolbox. Place a text box (TextBox1) on the UserForm. Click the SpinButton tool in the Controls Toolbox. Place a spin button (SpinButton1) on the UserForm. Click the CommandButton tool in the Controls Toolbox. Place a command button (CommandButton1) on the UserForm. On the View menu, click Properties Window.</li> With CommandButton1 selected, click Caption, type Close Now, and then press ENTER. This places the text on the command button.</li> Select the UserForm by clicking anywhere on the form. In the Properties window, click Caption, type Change Date, and then press ENTER.</li>  Right-click the command button, and then click View Code. Two lines of code are automatically entered for you. Between those two lines, type the following: UserForm1.Hide </li> Double-click UserForm1 (UserForm) on the Window menu to return to the UserForm.</li> On the UserForm, right-click the SpinButton, and then click View Code.</li>  Ensure that the Object list box (the drop-down list box in the upper-left of the window) shows SpinButton1. Click the Procedures list box (the drop-down list box in the upper-right of the window) and select SpinDown. Type the following code between the two lines placed automatically on the sheet. UserForm1.TextBox1.Text = DateValue(UserForm1.TextBox1.Text) - 1 </li>  Click the Procedures list box, and then select SpinUp. Type the following code between the two lines of code placed automatically on the sheet. UserForm1.TextBox1.Text = DateValue(UserForm1.TextBox1.Text) + 1 </li>  In the Visual Basic Editor, click Insert, and then click Module. On the module sheet, type the following code: Sub ShowForm UserForm1.TextBox1.Text = Date UserForm1.Show End Sub </li> In the Visual Basic Editor, click Tools, and then click Macros.

In the Macros dialog box, click ShowForm, and then click Run.</li></ol>

The UserForm appears. Click the UP ARROW to increment the date. Click the DOWN ARROW to decrement the date. Click the Close Now button to close the UserForm, and then return to the Visual Basic Editor.

<div class="references_section">