Microsoft KB Archive/213464

= XL2000: How to Programmatically Increment a Date With a Spinner =

Article ID: 213464

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213464





SUMMARY
In Microsoft Excel, you can use a spinner control to change values on a worksheet or in a Microsoft Visual Basic for Applications procedure. To use the spinner to increment and decrement a value over a wide range, you must set and use the spinner in conjunction with another value or cell to calculate both positive and negative values.

This article describes a Visual Basic macro that uses a spinner to increment or decrement a date in an edit box.



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 create and use a sample Visual Basic macro that uses a spinner control to increment and decrement a date value in an edit box, follow these steps:  Start Excel. In a new workbook, right-click any sheet tab. On the shortcut menu, click Insert. In the Insert dialog box, click MS Excel 5.0 Dialog, and then click OK. Click the Edit Box tool on the Forms toolbar, and then place an edit box on the dialog sheet. Click the Spinner tool on the Forms toolbar, and then place a spinner on the dialog sheet.</li> Press ALT+F11 to start the Visual Basic Editor.</li> On the Insert menu, click Module.</li>  On the module sheet, type or paste the following code: ' Defines variable called "OldSpin" as an integer, and makes it ' available to all subroutines. Public OldSpin As Integer

' This routine is assigned to the spinner to run when you choose the ' spinner. It will determine the difference between the current ' spinner value and OldSpin, and use the difference to increment or ' decrement the date in the edit box. Sub SpinDate ' Sets the edit box value based on the difference ' between OldSpin and the spinner value. DialogSheets(1).EditBoxes(1).Text = _ DateValue(DialogSheets(1).EditBoxes(1).Text) - OldSpin + _ DialogSheets(1).Spinners(1).Value ' Resets OldSpin to the spinner value. OldSpin = DialogSheets(1).Spinners(1).Value End Sub

' This routine initializes the spinner and OldSpin to a value of ' 15000, populates the edit box with today's date, and displays the ' dialog box. Sub ShowDialog ' Sets OldSpin to 15000. OldSpin = 15000 ' Sets the current spinner value to 15000. DialogSheets(1).Spinners(1).Value = OldSpin ' Sets the edit box to today's date. DialogSheets(1).EditBoxes(1).Text = Date ' Displays the dialog box. Dialogsheets(1).Show End Sub </li> Press ALT+F11 to return to Excel.</li> Click to select the dialog sheet.</li> Right-click the spinner control on the dialog sheet, and then click Assign Macro on the shortcut menu.</li> Click the SpinDate macro, and then click OK.</li> On the Tools menu, point to Macro, and then click Macros.</li> Click the ShowDialog macro, and then click Run. The spinner increments or decrements the date in the edit box. (By default, this date is the current date.) You can manually type a different date.</li></ol>

Keywords: kbdtacode kbhowto kbinfo kbprogramming KB213464

-

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

© Microsoft Corporation. All rights reserved.