How to Make Spinner Whose Minimum Value Is Less Than Zero (151324)



The information in this article applies to:

  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95
  • Microsoft Excel for Windows 5.0
  • Microsoft Excel 98 Macintosh Edition

This article was previously published under Q151324

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. 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. 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 and a Maximum Value of 20, 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.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto kbProgramming KB151324