+ Reply to Thread
Results 1 to 9 of 9

VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Exclamation VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    Hi all

    I'm creating a UserForm which will add data to my worksheet.
    I currently have checkboxes, which once the data is added the value of a checked box equals "Yes" and if unchecked it is "No"

    Is there anyway I can tell excel to change the added value from "Yes" to "1" and "No" to "0"?

    Otherwise, the easiest way will just be to add a Text Box and manually enter in the numbers.

    This is used so I can calculate the amount of times somebody was late, sick or on holiday.

    Thanks

  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: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    You could use something like this, which will put 1 in C10 if the checkbox is checked, 0 otherwise.
    Please Login or Register  to view this content.
    PS Are you sure your checkboxes return Yes/No? All of mine return True/False.
    Last edited by Norie; 12-05-2013 at 12:19 PM. Reason: To many i in my Iif.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    With if statements.
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  4. #4
    Registered User
    Join Date
    04-18-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    You're right they are "TRUE" and "FALSE"
    What does "Range" refer to? If I use C10, will every new field added overwrite the existing values in C10 or will it carry on with adding it to the next available row?

    *EDIT* If I remove the cell so only "" shows will this keep it in flow with adding to last row?

    Please Login or Register  to view this content.
    Last edited by jpoppet; 12-05-2013 at 12:31 PM. Reason: Another thought

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

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    C10 is a hard coded reference I used in the example code I posted.

    I don't know where you want the 1/0 to go so change it however you need to.

  6. #6
    Registered User
    Join Date
    04-18-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    I have added this;
    Please Login or Register  to view this content.
    but it's came up with this message;
    EXCELHELP.PNG

    When the Data is added it finds the last row and adds it there, is the range able to be limited to a collumn?

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

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    What code were you using previously to put the data from the userform on the worksheet?

    PS Range("") is wrong.

  8. #8
    Registered User
    Join Date
    04-18-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    Here's the full code.
    I'm dubious of deleting the frame_click but I'm pretty sure I don't need them?

    Please Login or Register  to view this content.
    Obviously you can see that I've changed the range, I created a name range for each column but it's just added all values in all rows of each column :P
    Last edited by jpoppet; 12-05-2013 at 12:59 PM. Reason: Forgot to Add

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

    Re: VBA, Userform with checkboxes - How to change the value from "Yes" to "1"

    Why have you created the ranges?

    You should just need to change this code,
    Please Login or Register  to view this content.
    like this.
    Please Login or Register  to view this content.
    Also, I think you can get rid of this, and the names.
    Please Login or Register  to view this content.
    PS It should be OK to delete the empty subs like Frame1_Click, in fact if you goto Debug>Compile Project they might disappear.

+ 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. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  2. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  3. Replies: 5
    Last Post: 10-12-2010, 06:46 AM
  4. Replies: 3
    Last Post: 07-27-2008, 06:31 AM
  5. Replies: 7
    Last Post: 05-13-2006, 05:02 PM

Tags for this Thread

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