+ Reply to Thread
Results 1 to 13 of 13

2 Numbers, 1 Spin Button

  1. #1
    Registered User
    Join Date
    05-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    2 Numbers, 1 Spin Button

    Okay so the background is a bit of the following, I'm trying to edit 1 number by an incriment value of 1, while another number is also edited using a backwards calculation dependant upon the value of the first number being edited. The problem here is two-fold: first the number in the second column doesn't change unless I click 'run', and secondly, the number it keeps returning is wrong (I think it's just doing it the once).

    The code I'm using is the following:


    Please Login or Register  to view this content.
    The first number, and the number the spinner is currently tied to is "D3", the second number that is supposed to change based on that value is M4. I also want to eventually tie a restriction that M4 cannot be less than zero for changes to occur in D3, but that might take a bit longer.

    The second code I have is trying to edit the minimum value of the spinbutton when the user clicks a checkbox (hence declaring they are done with this portion of the edit). The code I'm using is:

    Please Login or Register  to view this content.
    But it keeps returning 424 error. Any help with either of these things would be appreciated. Thanks. By the way.. if there is a list of functions that can be run in excel using VB that would be extremely helpful ^^
    Last edited by Evalis; 06-01-2010 at 02:23 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: 2 Numbers, 1 Spin Button

    A spinbutton is meant for situations in which you want to increase/decrease a number with a constant amount.
    If you want something else you'd better use a commandbutton:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    Hi Evalis,

    Try this...

    Please note that this is untested

    Please Login or Register  to view this content.
    Thanks,
    Ryan



    A word to the wise is infuriating. - Hunter S Thompson

  4. #4
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    ...and this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: 2 Numbers, 1 Spin Button

    The above code possesses the same problem as the original posting, in that the data does not update when I press the spin button. As far as using a command button is concerned, I fail to see the benefit, as I would essentially still have to create two command buttons that both perform 2 functions (which would be the same as using 'spinup' and 'spindown'), though I might give this a try if it will solve the fact that the numbers don't update.

  6. #6
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    It's ok...the code I gave you doesn't do what you want anyway. I did test the code below and it worked for me, with the exception of the fact that you didn't specify what you wanted to happen when the value in D3 is greater than 17 but less than 100.

    Now, as for it not working when you press the spin button. Make sure that this code is placed in the class module for the worksheet in which the spin button is embedded and that you are not in design mode. These events will not be triggered if the code is placed in a standard code module

    Updated Code:

    Please Login or Register  to view this content.
    Last edited by Ryan Murtagh; 05-20-2010 at 12:56 PM.

  7. #7
    Registered User
    Join Date
    05-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: 2 Numbers, 1 Spin Button

    I must be retarded. What do you mean by embedded?

  8. #8
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    Your not retarded. What I should have said was that any time you place a control (like a spinner or a textbox) onto a worksheet, the macros that you use to drive that control have to live on that worksheet's class module. Each sheet has it's own class module, and you can access the class module by going into VBA (hit Alt+F11) and double clicking on the sheet's name in the Project window, or by just double clicking on the control (your spinner).

    If you want to attach an example workbook of your project, I'd be happy to take a look at it for you.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: 2 Numbers, 1 Spin Button

    Ryan,

    This syntax is not valid, and if it were, it would have gaps at the whole numbers:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    05-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: 2 Numbers, 1 Spin Button

    I still don't quite understand. The macro's exist on both the module and on the sheet. Maybe there's something I'm missing though. The copy of the worksheet is here. The stats sheet is the one I'm attempting to manipulate. Thanks again for your patience ^^
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    shg you are quite right. I'm not sure why I didn't get a syntax error when I ran it, but I definitely should have caught the fact that the cell was not updating correctly.

    Nevertheless...Evalis, I downloaded your workbook and the reason that your macros aren't working is because you are using the wrong kind of spinner. There are two types of controls that you can put onto a worksheet: Forms Controls and ActiveX controls. You can go into Excel's help documentation for a pretty good explanation of the difference between the two.

    I think there may be a non-VBA solution here. I'm going to take your workbook home and play with it for a bit, free of distraction, so that I don't post any more junk solutions for you. If someone comes up with a suitable fix for you in the meantime, then good on them. I will still post a solid solution for you to ease my karma after leading you in the wrong direction earlier.

  12. #12
    Registered User
    Join Date
    05-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: 2 Numbers, 1 Spin Button

    No this works now, thanks! I'm not sure about the me. command but that may have given me an error simply because it also was a form control. I'm still working on this, and have a lot to go, but the spinners are working now =D
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    05-20-2010
    Location
    Fresno, CA
    MS-Off Ver
    2003, 2010
    Posts
    58

    Re: 2 Numbers, 1 Spin Button

    Best of luck with your project!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1