+ Reply to Thread
Results 1 to 5 of 5

combinations of checkboxes and executing commands

  1. #1
    Registered User
    Join Date
    08-19-2005
    Posts
    58

    combinations of checkboxes and executing commands

    let's say i have 4 checkboxes, a, b, c, and d. i want to do some calculation (e.g. the average) based on what is selected.

    in other words, if a and b are chosen, it will be the average of a and b. if a, b, and c are chosen, then it will be the average of a, b, and c.

    now, of course, if i hard code this as a bunch of if-then statements, it will be cumbersome, as i'll have to code every single possible combination (a; b; c; d; a and b; a and c; etc.).

    is there a more efficient way to do this?

    thanks.

    edit: nevermind, i got it. i defined variables so that it is a number if the checkbox is checked, and 0 otherwise. then i defined sum and count as the sum of those variables.
    Last edited by dreamz; 10-27-2005 at 05:53 PM.

  2. #2
    Registered User
    Join Date
    08-19-2005
    Posts
    58
    nevermind, i have a question.

    how do i make it so that the formula is pasted into a cell rather than a value?

  3. #3
    Alok
    Guest

    RE: combinations of checkboxes and executing commands

    if chkA.value then
    wcount=wcount+1
    dValue = dValue + A
    endif
    if chkB.value then
    wcount=wcount+1
    dValue = dValue + B
    endif
    if chkC.value then
    wcount=wcount+1
    dValue = dValue + C
    endif

    and so on.
    then average is dvalue/wcount.
    Hope this helps.

    Alok

    "dreamz" wrote:

    >
    > let's say i have 4 checkboxes, a, b, c, and d. i want to do some
    > calculation (e.g. the average) based on what is selected.
    >
    > in other words, if a and b are chosen, it will be the average of a and
    > b. if a, b, and c are chosen, then it will be the average of a, b, and
    > c.
    >
    > now, of course, if i hard code this as a bunch of if-then statements,
    > it will be cumbersome, as i'll have to code every single possible
    > combination (a; b; c; d; a and b; a and c; etc.).
    >
    > is there a more efficient way to do this?
    >
    > thanks.
    >
    >
    > --
    > dreamz
    > ------------------------------------------------------------------------
    > dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
    > View this thread: http://www.excelforum.com/showthread...hreadid=479943
    >
    >


  4. #4
    Alok
    Guest

    Re: combinations of checkboxes and executing commands

    Hi,
    The way to do it is
    Worksheets("abc").Cells(1,2).FormulaR1C1="=Sum(myrange)"

    By the way when you are asking a new question it is advisable to start a new
    thread. Otherwise people may not pay attention to your new query. :-)

    Alok


    "dreamz" wrote:

    >
    > nevermind, i have a question.
    >
    > how do i make it so that the formula is pasted into a cell rather than
    > a value?
    >
    >
    > --
    > dreamz
    > ------------------------------------------------------------------------
    > dreamz's Profile: http://www.excelforum.com/member.php...o&userid=26462
    > View this thread: http://www.excelforum.com/showthread...hreadid=479943
    >
    >


  5. #5
    Registered User
    Join Date
    08-19-2005
    Posts
    58
    thanks, alok. i wrote something like this. to be clear, i declared tricor and oos as ranges.

    Please Login or Register  to view this content.
    and that didn't work. it said type mismatch error. what did i do wrong? (don't worry about the count stuff for now. i didn't include it in the formula because i'm still testing it).


    and it's not an entirely new question since it's just a problem i encountered when trying to implement the solution to this one. i don't like creating multiple threads, as it seems like spam.

+ 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