XL: How to Make Spinner Whose Minimum Value Is Less Than Zero

ID: Q151324

The information in this article applies to:

SUMMARY

In the products listed at the beginning of this article, the spinner control that is on the Forms toolbar has a minimum value of zero. This article includes a Microsoft Excel Visual Basic for Applications macro example that demonstrates how you can use a spinner control that appears to allow negative numbers.

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

In the following example, you create a spinner control that appears to have a minimum value of -10 and a maximum value of 10. The spinner control stores its result in cell A1.

1. Create a new workbook.

2. Right-click (or CONTROL-click) the toolbar area in Microsoft Excel.

   Click Forms on the menu to display the Forms toolbar.

3. Click the spinner control on the Forms toolbar and draw the spinner
   control next to cell A1 on your worksheet.

4. Double-click the spinner control to display the Format Object dialog
   box. Click the Control tab. Type a Minimum Value of "0" (without the
   quotation marks) and a Maximum Value of "20" (without the quotation
   marks), and click OK.

   NOTE: You set the Maximum to 20 because the difference between the
   minimum and the maximum values that you want to use is 20 (that is,
   10-(-10)=20).

5. Right-click (or CONTROL-click) the spinner control and click Assign
   Macro.

6. Click New in the Assign Macro dialog box.

7. Type the following macro in the module:

      Const Diff = 10

      Sub Spinner1_Change()
          Range("A1").Value = _
              ActiveSheet.Spinners("Spinner 1").Value - Diff
      End Sub

   NOTE: The constant Diff is equal to the difference between 0 and the
   minimum value that you want to use (that is, 0-(-10) = 10).

8. Activate the worksheet that contains the spinner control. Select cell
   A1. Test the spinner control by clicking it. You should see values in
   cell A1 that range between -10 and 10.

Additional query words: 5.00 5.00a 5.00c 7.00 8.00 XL97 XL98 XL7 XL5 Increment Minimum
Keywords          : kbprg kbdta kbdtacode PgmHowto KbVBA 
Version           : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,5.0a,98
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: May 18, 1999