+ Reply to Thread
Results 1 to 21 of 21

if statement with checkboxes

  1. #1
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    if statement with checkboxes

    Hi I am VERY new to Excel VB and require some assistance

    I have used a large number of form check boxes which i have linked to a various cells (say A1:A10) on a worksheet (call it worksheet 1).

    When any of the check boxes in the range is checked (ie TRUE) I want to write "True" in another cell in another worksheet (say worksheet 2)

    If more than one checkbox in the range is checked (True). I want it to write "True" in another cell in the worksheet in the next available cell. eg if checkbox 1 is checked then is will write in cell A1, if checkbox 2 is checked it will write in cell A2 etc. So it must just write the text in the next available cell. Not all the checkboxes may necessarily be checked (if only checkbox 3 is checked then it must still write in cell A1)

    I have tried to write an if statement for this but I keep getting errors.

    Can anyone help???

  2. #2
    Registered User
    Join Date
    02-13-2012
    Location
    East-London, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: if statement with checkboxes

    Please upload the file?

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    The attached uses some formula to determine checkbox select and displays an ordered list of those checked.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Thanks this looks good so far you get the idea of what I would like, but unfortunately I cant see your code?? how did you do it?

    Also I would like the text to be place in another worksheet (eg Worksheet 2)

    Lastly, I see the text changes according to numerical value eg if check box 4 is selected then checkbox 3 the texts shows textbox 3 in the cell above text box 4. I would the text to reflect the sequence in which the checkbox was selected.

    Thank you SO SO SO much

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    There is no code. It was done with formula.

    The example has code and stores the selections in order. I have used a named range on the activesheet so you can see the results whilst testing. All you need to do then is alter then named range to another location.

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

  6. #6
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Hi again,

    For a newbie like me your code is a bit too complicated. I have attached my file. If you see in the worksheet "Maintenance Plan" there are numerous checkboxes indicating whether a a major overhaul etc for a particular year was done or not (unchecked means not done, checked means done).

    What I would like to do is, once the box is checked (ie a major overhaul was done etc), then this information is updated on the Plant History worksheet. Ie the year, the unit, the comment, etc. The comment must reflect the type of maintenance done eg Major over haul, speed damper etc.

    Also on the maintenance worksheet, if I click the button saying unit 6. It scrolls to the heading unit 6, but then you no longer have the buttons on the left hand side. I want to keep the pane on the left such that the buttons are always visible.

    Hope you can help.

    Thank you!
    Thanks

  7. #7
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Please see attached file
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Can any one help?Please!!!

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    You can assign all the checkboxes to this routine.

    Please Login or Register  to view this content.
    Unlike the previous example this will not remove any items from the history sheet, it simply appends. Although unchecked items have a prefix on the comment so you can find them easily.


    If you want your buttons to remain is view when viewing Units lower down the sheet you will need to place them in the top part of the frozen pane.
    Or create a dedicated toolbar (xl2003) or custom ribbon(2007+)

  10. #10
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Hi thanks but I keep getting a run time error.

    Can you please adapt the code in the file attached in the previous post on one of the check boxes so I can see how it is done?

    Thank you

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    See attached
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Hi Andy,

    Ok I think I have figured your last comment out. It works great but how can I keep it such that it appends when checked but removes the insert in "plant history" when unchecked. Or is that a mission?

    Thanks

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    So if somebody clicks a checkbox you keep a record of it. But if they then subsequently uncheck you don't care about keeping a history of that?
    If that's the case why the need to store clicks in order?

  14. #14
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Yes because if someone unclicks it it means the job was not done therefore I dont want to keep history of that. I have adapted your code to make a msg box show to warn the person that the box will be unchecked and hence the record of it being checked will be removed. I want to store the clicks in chronological order. Ideally a person would click a checkbox in 2011 before checking it in 2012. So i would like the plant history to reflect the dates sequentially. So I dont want the code to switch the sequence of the checkbox number like the previous code did (your code shifted checkbox 1 to always be first-this might not always be the case in my situation).

    Sorry for the confusion

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,450

    Re: if statement with checkboxes

    This will append a checked item or remove an unchecked one.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    awe its not working! it seems to work in your file I tried to copy paste the macro into my file but it doesnt seem to work.

    sorry I am completely useless at this!

  17. #17
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    awe its not working! it seems to work in your file I tried to copy paste the macro into my file but it doesnt seem to work.

    sorry I am completely useless at this!

  18. #18
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    THANK YOU SO MUCH you really helped its working great now!

  19. #19
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Hi Andy,

    Any chance you can adapt the code such that once the checkbox is checked the information appends to the top of the table instead of at the bottom. This is to ensure that the latest information is at the top and the older information is at the bottom of the table.

    Thanks
    Regards

  20. #20
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    Hi there

    What is wrong with the following code statement? I keep getting an error. It says that the 'item with the specified name wasn't found'

    Set shpCheckbox = ActiveSheet.Shapes(Application.Caller)

    Can anyone please help.

    Thanks

  21. #21
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: if statement with checkboxes

    can anyone help please?????????

+ 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