• changing true / false to yes/no in vb

    Author
    Topic
    #470471

    i’m using a user form that has a checkbox, when i check the checkbox the result in my spreadsheet is either true or false, but i need it to be yes or no.

    i have tried numerous codes that are out there in the search database but i’m doing something wrong can anybody assist please….

    Code:
    if me.checkbox1.value = "" then
    me.checkbox7.setfocus
     end if
    

    that just gives me true or false

    I have also tried this

    Code:
    Private Sub cmdenter_click()
    If checkbox1 = True Then
    ActiveCell.Offset(0, 0).Value = "Yes"
    Else
    ActiveCell.Offset(0, 0).Value = "No"
    End If
    If checkbox2= True Then
    ActiveCell.Offset(0, 1).Value = "Yes"
    
    End If
    End If
    
    End Sub
    

    I need the output to go into column 52 or BB and it has to progress downward from bb1 to bb2 etc for every new entry.

    its 4 am and i have been at this since noon – can anybody help me out

    Viewing 5 reply threads
    Author
    Replies
    • #1235247

      Try this,

      Code:
      Private Sub cmdenter_click()
          Cells(1,52) = iif(checkbox1 ,"Yes","No")
          Cells(2,52) = iif(checkbox2 ,"Yes","No")
          '*** Etc... ***
      End Sub
      

      Since a check box returns True/False you don’t have to compare it to anything!

      Hope this helps and you can get some sleep.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1235300

      sure but wouldn’t I have to do that for every row in the spreadsheet?

      I tried this code below too but it still puts in tru or false

      Code:
      Private Sub cmdenter_click()
      If checkbox1 Then
         Cells(Rows.Count,"BB").End(xlUp).Offset(1).Value = "Yes"
      Else
         Cells(Rows.Count,"BB").End(xlUp).Offset(1).Value = "No"
      End If
      
      End Sub
      
      

      any other ideas?

      • #1235319

        I tried this code below too but it still puts in tru or false

        If Yes displays as True and No displays as false, perhaps Conditional Formatting has been applied to those cells?

    • #1235336

      I’m a little confused .

      How many check boxes do you have on your userform?
      Are you always adding to the end of the list like in your last post?
      Could you post a screen shot of your userform or the excel workbook.
      It’s often hard to understand a problem from descriptions.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1235343

      ok guy he it all is gentleman all of it in it’s entirety. If you see anything that you think you can achieve better please by all means alter the code and let me know. Because time is running out here. thank you all for your time and efforets it is greatly appreciated.

    • #1235350

      Ok,

      I’ve looked at your code and here’s a couple of suggestions: {I’ve change some of your code as examples}

      1. Indent your code for easier reading.
      2. Me. is redundant when you’re coding in a form leave it out…less to read through.
      3. Rename all your controls: CheckBox3 is not helpful when reading code. A better name would be ckboxAM since this is the check box for AM that way when reading the code you know what you’re referencing especially when you have 20 check boxes on the form! the same goes for text boxes txttr is better but again relies on memory txtTroubleReported is much better. Yes it’s more typing but it will make things much easier when you come back to this project after not looking at it for a couple of months.
      4. When referencing a whole list items with the same prefix use the With clause. Again saves typing and is easier to read – See example in code With WS … End With.
      5. I’ve changed two of the Check boxes you’re writing to the worksheet to enter “Yes” or “No” vs “True” or “Fasle”.
      6. I’ve also commented out several lines of code which would not compile. Use the Debug -> Compile VBA option on the menus in the VBA editor to check your code for problems.

      I hope this helps. Good Luck.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1235360

      thank you again for your time and knowledge. As you can tell I’m not that good. Heck I just dabble in it. So any and all help is appreciated.

    Viewing 5 reply threads
    Reply To: changing true / false to yes/no in vb

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: