CheckBox Userform checked or unchecked based on cell

  • Good morning people,


    I have made a userform with a listbox, and I managed to add a checkbox in my userform. However I want the checkbox to be linked with the cell (textbox).
    If I check the checkbox and update the listbox the cell value will be "True", which is good. But once I select a different item in the listbox the checkbox stays checked, even though the cell value of that item is still on "False".


    Thanks in advance.


    This is the code:

    Code
    Dim RowCount As Long
      RowCount = Worksheets("Data").Range("X1").CurrentRegion.Rows.Count
    With Worksheets("Data").Activate
      ActiveCell.Offset(0, i).Range("X1").Select
      ActiveCell.Value = Me.CheckBox1.Value
  • Re: CheckBox Userform checked or unchecked based on cell


    Attach an example workbook. It's not clear whether you are referring to a fixed cell. You certainly do not need to use Select though

  • Re: CheckBox Userform checked or unchecked based on cell


    Thanks for replying.



    What I basically want is that if a cell value is "JA" the checkbox should be checked and when it is empty " " then the checkbox should not be checked.


    I tried many codes but it doesn't seem to work:


    Code
    If Range("X1").Value = "JA" Then
        ActiveSheet.CheckBoxes("Check Box 7").Value = xlOn
     Else
        ActiveSheet.CheckBoxes("Check Box 7").Value = xlOff
    End If


    I can't seem to attach the file; it gives me an error every time I am trying to upload it. My apologies.

  • Re: CheckBox Userform checked or unchecked based on cell


    Try this


    Code
    Option Explicit
    
    
    Private Sub UserForm_Initialize()
    Me.CheckBox2.Value = ActiveSheet.Range("X1").Value = "JA"
    End Sub
  • Re: CheckBox Userform checked or unchecked based on cell


    Thanks for the reply, I really appreciate your help and patience.


    I tried but it still doesn't work. I will try to explain it in a better way. So I have a userform with a listbox. And I have a checkbox. If I check the checkbox and press save/update it will fill a cell with the value "JA" (Yes), so that is good. But the problem however is that if I select another item in the listbox that hasn't the cell value filled with "JA" it shows me the checkbox checked, while it should be unchecked. So what I want is that the checkbox is linked with the value of the cells in the listbox, so if a cell contains "JA" the checkbox is checked and if it doesn't contain any value the checkbox isn't checked.


    See picture attached with the list box and the checkbox in a red circle.

  • Re: CheckBox Userform checked or unchecked based on cell


    Yes I know, my apologies. I have tried to attach a file but ozgrid gives me an error uploading the excel file...


    I have uploaded the file here: https://ufile.io/c7e15


    Thanks again for your help and patience :)

  • Re: CheckBox Userform checked or unchecked based on cell


    I'm not using that site, I get a security warning.


    Try zipping the file before uploading here

  • Re: CheckBox Userform checked or unchecked based on cell


    I would just clear the cell value when the listbox changes and/or when the userform is opened. Then run the code to update whatever needs to be updated when either the cell of userform change. May just bee that your if/then checks are not coverything all options.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!