+ Reply to Thread
Results 1 to 8 of 8

dividing a number amongst 3 textboxses with "1" number at a time

  1. #1
    Registered User
    Join Date
    11-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    dividing a number amongst 3 textboxses with "1" number at a time

    Hi all

    Making slow, but steady progress with my "learn yourself VBA programming" i never the less has run into a problem i would really appriciate some help soving...

    The case is as follows... making a userform, i have a textbox that the user puts a number into (something like 1 to 1000, but always an integer). Then the user checks of any number (and combination) of 3 checkbox's i have in the userform. Below the checkboxes are 3 textboxes, one for each checkbox... what i need is a code that will take the integer number from the first textbox and divede that number amongst the appropriate textboxes, with 1 at a time... and ofc only assign numbers to the textboxes with checkboxes ticket of (true)??

    Just to clearify, ill try and make up 2 scenarios..

    1. user enters 38 in the first textbox... and theb ticks off all 3 checkboxes... then the code should divide the number of 38 to the 3 textboxes, so that textbox2 ends up with the value of 13, textbox3 = 13 and last textbox4 = 12.... (13 + 13 + 12 = 38)

    2. user stil enters 38, but this time only ticks of checkbox 1 and checkbox 3... then both textbox2 and textbox4 should end up with the value of 19...


    Anyone got an idea how to solve this??

    my own thoughts are that it must be something in the line of getting the code to reckognise wich checkboxes are true and then lopping through the corresponding textboxes as many times as the number entered in textbox 1, each time adding +1 to the textbox value... but bugger, i cant "code" that (yet...)... any help will be greatly appriciatet...


    best regards

    PS. the eventhandler part i think i can handle... so only the code for the assigning of numbers are needed
    Last edited by Leandrial; 12-05-2012 at 06:10 AM. Reason: clearification

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Why not just count the no of checkboxes that are true and divide the number entered by that?
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Try this code in your userform

    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  4. #4
    Registered User
    Join Date
    11-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Hi Sean and Norie. thx for the suggestions... but i cant use decimal values in my textboxes.. the initial number (38 and 39 in the post) represents hard real ife objekts that cant be diveded into peices... so the have to be divided as "integer"...

  5. #5
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Hi -

    Try this one, please adjust as needed

    Please Login or Register  to view this content.
    Regards,
    Event

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    I should have added that the values would need rounding if required.

  7. #7
    Registered User
    Join Date
    11-24-2012
    Location
    Denmark
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Hi event

    Txh for the suggestion...

    Funny stuff was that after posting here i managed to figure out a way to do it (kinda like when you take your broken electrical gadget to the store and says "Hi, this one's broken", and the repair guy there turns it on and everything works just fine....)...

    Heres how i managed to get it to work... please feel free to comment... initially my thoughts where that "my way" where simpler then your suggestion... but that also makes me suspect that mine could have som "build-in" flaws.... so please comment if you c any..

    Please Login or Register  to view this content.
    Again, thank you very much for the reply.

    Ps. i have marked this one as solved.
    Last edited by Leandrial; 12-06-2012 at 04:40 AM. Reason: forgot code tags

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: dividing a number amongst 3 textboxses with "1" number at a time

    Hi -

    Glad you managed it after 7+ hrs of my posting.

    if you want some flaws, open your form and click any checkbox without entering value in textbox, so go into that and fix.

    Regards,
    Event

+ 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