+ Reply to Thread
Results 1 to 4 of 4

Assign number to combination of checkboxes

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2012
    Location
    Los Angeles USA
    MS-Off Ver
    Excel Office 365
    Posts
    80

    Assign number to combination of checkboxes

    I have 3 conditions set with checkboxes, I would like to generate a number between 1 and 7 which would show what combination of checkboxes have been checked. Is there a simpler way, rather than use of If statements to do this?
    Combinations selected
    1 - 1
    2 - 2
    3 - 3
    4 - 1 & 2
    5 - 1 & 3
    6 - 2 & 3
    7 -1 & 2 & 3

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Assign number to combination of checkboxes

    Can the order in which the checkboxes add up to 7 be changed? You could just use Binary for this if so.
    Checkboxes A B and C

    Logic:
    A B C
    0 0 1 = 1
    0 1 0 = 2
    0 1 1 = 3
    1 0 0 = 4
    1 0 1 = 5
    1 1 0 = 6
    1 1 1 = 7
    If A is checked, 1
    if B is checked, 2
    If C is checked, 4

    =SUM(ABC)

    Something like...and I may be wrong on that variable, I'm bad at arrays
    
    dim v1(2) as variant
    dim vResult as integer
    
    if checkbox1.checked = true then v1(0)=1
    else
    v1(0)=0
    end if
    
    if checkbox2.checked = true then v1(1)=2
    else
    v1(1)=0
    end if
    
    if checkbox3.checked = true then v1(2) =4
    else
    v1(2)=4
    end if
    
    vResult = v1(0)+v1(1)+v1(2)
    
    msgbox vResult
    Last edited by Speshul; 11-10-2014 at 04:58 PM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Assign number to combination of checkboxes

    Well, I did use a mess of IFs, VLOOKUP and IFERROR.

    Formula: copy to clipboard
    =IFERROR(VLOOKUP(IF(AND(A1=TRUE,A2=TRUE,A3=TRUE),"G",IF(AND(A2=TRUE,A3=TRUE),"F",IF(AND(A1=TRUE,A3=TRUE),"E",IF(AND(A1=TRUE,A2=TRUE),"D",IF(A3=TRUE,"C",IF(A2=TRUE,"B",IF(A1=TRUE,"A",""))))))),M1:N7,2,0),"")


    Another way using LOOKUP

    Formula: copy to clipboard
    =LOOKUP(A1&A2&A3,{"FALSEFALSEFALSE","FALSEFALSETRUE","FALSETRUEFALSE","FALSETRUETRUE","TRUEFALSEFALSE","TRUEFALSETRUE","TRUETRUEFALSE","TRUETRUETRUE";0,3,2,6,1,5,4,7})
    Attached Files Attached Files
    Last edited by newdoverman; 11-10-2014 at 05:29 PM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  4. #4
    Registered User
    Join Date
    01-18-2012
    Location
    Los Angeles USA
    MS-Off Ver
    Excel Office 365
    Posts
    80

    Re: Assign number to combination of checkboxes

    Thanks for the approaches, I'll give them a try, and see which one works best for my application.
    Al

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Please help! macro code needed to assign to command button to check a column of checkboxes
    By cnbv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2013, 04:47 AM
  2. Assign Macro(s) to multiple checkboxes
    By realdealsxbl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2012, 09:14 PM
  3. Want to assign combination hotkeys to activate macro filters in 2003 & 2010+
    By Red2Black in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2011, 08:20 PM
  4. How do I assign macro codes to multiple checkboxes
    By spamunch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-14-2011, 11:05 AM
  5. Replies: 7
    Last Post: 12-18-2008, 07:34 PM

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