+ Reply to Thread
Results 1 to 16 of 16

textbox and checkbox

Hybrid View

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    textbox and checkbox

    I have a checkbox and multiple textbooks let say about 10.When the checkbox=true , i will be able to write data inside. if checkbox=false, it will be lock. THe code below work when only i click the button. How do i make it work immdiately upon when the checkbox=false?

    Private Sub CheckBox1_Click()
    
    If CheckBox1.Value = True Then
      TextBox1.Enabled = True
      Else
      TextBox1.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox2.Enabled = True
      Else
      TextBox2.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox3.Enabled = True
      Else
      TextBox3.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox4.Enabled = True
      Else
      TextBox4.Enabled = False
    End If
    
    End Sub
    
    
    Private Sub CommandButton1_Click()
    
    Sheet1.Range("E7").Value = TextBox1.Value
    Sheet1.Range("E8").Value = TextBox3.Value
    Sheet1.Range("E9").Value = TextBox5.Value
    Sheet1.Range("E10").Value = TextBox7.Value
    Sheet1.Range("E11").Value = TextBox9.Value
    Sheet1.Range("E7").Value = TextBox2.Value
    Sheet1.Range("E7").Value = TextBox4.Value
    Sheet1.Range("E7").Value = TextBox6.Value
    Sheet1.Range("E7").Value = TextBox8.Value
    Sheet1.Range("E7").Value = TextBox10.Value
    
    
    End Sub


    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:16 AM.

  2. #2
    Forum Contributor
    Join Date
    06-14-2008
    Posts
    153

    Re: textbox and checkbox

    Put the code in CheckBox1_Change() instead of CheckBox1_Click.
    Welcome to: http://www.exceldigest.com/myblog/
    "Excel help for the rest of us"

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    still the textbox cant be lock upon running








    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:17 AM.

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    if you use a userform the idea given by se1429 works
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  5. #5
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    I am new to this, maybe u wanna take a look at my file.










    Go www.cashcrate.com/3866888 to earn cash online!!!
    Attached Files Attached Files
    Last edited by ngkj; 07-17-2012 at 05:19 AM.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    see if it helps you, please continue with the rest of your textboxes/checkboxes
    Private Sub CheckBox1_Change()
    If CheckBox1.Value = True Then
      TextBox1.Enabled = True
      Else
      TextBox1.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox2.Enabled = True
      Else
      TextBox2.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox3.Enabled = True
      Else
      TextBox3.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox4.Enabled = True
      Else
      TextBox4.Enabled = False
    End If
    
    End Sub
    
    
    Private Sub CommandButton1_Click()
    
    Sheets("Sheet1").Range("E7").Value = TextBox1.Value
    Sheets("Sheet1").Range("E8").Value = TextBox3.Value
    Sheets("Sheet1").Range("E9").Value = TextBox5.Value
    Sheets("Sheet1").Range("E10").Value = TextBox7.Value
    Sheets("Sheet1").Range("E11").Value = TextBox9.Value
    Sheets("Sheet1").Range("F7").Value = TextBox2.Value
    Sheets("Sheet1").Range("F8").Value = TextBox4.Value
    Sheets("Sheet1").Range("F9").Value = TextBox6.Value
    Sheets("Sheet1").Range("F10").Value = TextBox8.Value
    Sheets("Sheet1").Range("F11").Value = TextBox10.Value
    End Sub
    
    Private Sub UserForm_Activate()
    CheckBox1.Value = 1
    End Sub

  7. #7
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    Yup! It works! thanks P.S just to ask another thing. If checkbox is not check the data will not be change, how can i do that?








    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:20 AM.

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    Quote Originally Posted by ngkj View Post
    Yup! It works! thanks P.S just to ask another thing. If checkbox is not check the data will not be change, how can i do that?
    in this case, why you use this code in your first post?!
    Private Sub CheckBox1_Click()
    
    If CheckBox1.Value = True Then
      TextBox1.Enabled = True
      Else
      TextBox1.Enabled = False
    End If

  9. #9
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    i was new to this so i don't really know, sorry. the error i get was that even thought the checkbox is uncheck the data still change upon clicking the button.
    this is me current codes
    Private Sub CheckBox1_Change()
    
    If CheckBox1.Value = True Then
      TextBox1.Enabled = True
      Else
      TextBox1.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox2.Enabled = True
      Else
      TextBox2.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox3.Enabled = True
      Else
      TextBox3.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox4.Enabled = True
      Else
      TextBox4.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox5.Enabled = True
      Else
      TextBox5.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox6.Enabled = True
      Else
      TextBox6.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox7.Enabled = True
      Else
      TextBox7.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox8.Enabled = True
      Else
      TextBox8.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox9.Enabled = True
      Else
      TextBox9.Enabled = False
    End If
    
    If CheckBox1.Value = True Then
      TextBox10.Enabled = True
      Else
      TextBox10.Enabled = False
    End If
    
    End Sub
    
    
    Private Sub CheckBox2_Change()
    
    If CheckBox2.Value = True Then
      TextBox11.Enabled = True
      Else
      TextBox11.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox12.Enabled = True
      Else
      TextBox12.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox13.Enabled = True
      Else
      TextBox13.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox14.Enabled = True
      Else
      TextBox14.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox15.Enabled = True
      Else
      TextBox15.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox16.Enabled = True
      Else
      TextBox16.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox17.Enabled = True
      Else
      TextBox17.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox18.Enabled = True
      Else
      TextBox18.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox19.Enabled = True
      Else
      TextBox19.Enabled = False
    End If
    
    If CheckBox2.Value = True Then
      TextBox20.Enabled = True
      Else
      TextBox20.Enabled = False
    End If
    
    End Sub
    
    Private Sub CheckBox3_Change()
    
    If CheckBox3.Value = True Then
      TextBox21.Enabled = True
      Else
      TextBox21.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox22.Enabled = True
      Else
      TextBox22.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox23.Enabled = True
      Else
      TextBox23.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox24.Enabled = True
      Else
      TextBox24.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox25.Enabled = True
      Else
      TextBox25.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox26.Enabled = True
      Else
      TextBox26.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox27.Enabled = True
      Else
      TextBox27.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox28.Enabled = True
      Else
      TextBox28.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox29.Enabled = True
      Else
      TextBox29.Enabled = False
    End If
    
    If CheckBox3.Value = True Then
      TextBox30.Enabled = True
      Else
      TextBox30.Enabled = False
    End If
    
    End Sub
    
    Private Sub CommandButton1_Click()
    
    'Checkbox1
    Sheets("Sheet1").Range("E7").Value = TextBox1.Value
    Sheets("Sheet1").Range("F7").Value = TextBox2.Value
    Sheets("Sheet1").Range("E8").Value = TextBox3.Value
    Sheets("Sheet1").Range("F8").Value = TextBox4.Value
    Sheets("Sheet1").Range("E9").Value = TextBox5.Value
    Sheets("Sheet1").Range("F9").Value = TextBox6.Value
    Sheets("Sheet1").Range("E10").Value = TextBox7.Value
    Sheets("Sheet1").Range("F10").Value = TextBox8.Value
    Sheets("Sheet1").Range("E11").Value = TextBox9.Value
    Sheets("Sheet1").Range("F11").Value = TextBox10.Value
    
    'Checkbox2
    Sheets("Sheet1").Range("I7").Value = TextBox11.Value
    Sheets("Sheet1").Range("J7").Value = TextBox12.Value
    Sheets("Sheet1").Range("I8").Value = TextBox13.Value
    Sheets("Sheet1").Range("J8").Value = TextBox14.Value
    Sheets("Sheet1").Range("I9").Value = TextBox15.Value
    Sheets("Sheet1").Range("J9").Value = TextBox16.Value
    Sheets("Sheet1").Range("I10").Value = TextBox17.Value
    Sheets("Sheet1").Range("J10").Value = TextBox18.Value
    Sheets("Sheet1").Range("I11").Value = TextBox19.Value
    Sheets("Sheet1").Range("J11").Value = TextBox20.Value
    
    'Checkbox3
    Sheets("Sheet1").Range("M7").Value = TextBox21.Value
    Sheets("Sheet1").Range("N7").Value = TextBox22.Value
    Sheets("Sheet1").Range("M8").Value = TextBox23.Value
    Sheets("Sheet1").Range("N8").Value = TextBox24.Value
    Sheets("Sheet1").Range("M9").Value = TextBox25.Value
    Sheets("Sheet1").Range("N9").Value = TextBox26.Value
    Sheets("Sheet1").Range("M10").Value = TextBox27.Value
    Sheets("Sheet1").Range("N10").Value = TextBox28.Value
    Sheets("Sheet1").Range("M11").Value = TextBox29.Value
    Sheets("Sheet1").Range("N11").Value = TextBox30.Value
    
    
    
    End Sub
    
    
    Private Sub UserForm_Activate()
    
    CheckBox1.Value = 1
    CheckBox2.Value = 1
    CheckBox3.Value = 1
    
    End Sub








    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:21 AM.

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    no problem at all, we are here to help each other and to learn!
    so, please the test file attached, it works for me, if the checkbox is checked you can type in yr textboxes if not...not!
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    yup! i am a student new to this it can work but when it's uncheck the actual data get remove/change








    Go www.cashcrate.com/3866888 to earn cash online!!!
    Attached Files Attached Files
    Last edited by ngkj; 07-17-2012 at 05:21 AM.

  12. #12
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    are you working in userform, aren't you?
    when you display yr userform, the checkbox1 is checked, so you can type/add text in yr textboxes, if checkbox1 is unchecked the textboxes(1...) are locked you can not add/delete anything in them!

  13. #13
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    yep i know, i wanted to change the data in the worksheet and i solved it! and better ways others than this?
    Private Sub CommandButton1_Click()
    
    'Checkbox1
    If CheckBox1.Value Then
        Sheets("Sheet1").Range("E7").Value = TextBox1.Value
        Sheets("Sheet1").Range("F7").Value = TextBox2.Value
        Sheets("Sheet1").Range("E8").Value = TextBox3.Value
        Sheets("Sheet1").Range("F8").Value = TextBox4.Value
        Sheets("Sheet1").Range("E9").Value = TextBox5.Value
        Sheets("Sheet1").Range("F9").Value = TextBox6.Value
        Sheets("Sheet1").Range("E10").Value = TextBox7.Value
        Sheets("Sheet1").Range("F10").Value = TextBox8.Value
        Sheets("Sheet1").Range("E11").Value = TextBox9.Value
        Sheets("Sheet1").Range("F11").Value = TextBox10.Value
     End If
    
    'Checkbox2
    If CheckBox2.Value Then
        Sheets("Sheet1").Range("I7").Value = TextBox11.Value
        Sheets("Sheet1").Range("J7").Value = TextBox12.Value
        Sheets("Sheet1").Range("I8").Value = TextBox13.Value
        Sheets("Sheet1").Range("J8").Value = TextBox14.Value
        Sheets("Sheet1").Range("I9").Value = TextBox15.Value
        Sheets("Sheet1").Range("J9").Value = TextBox16.Value
        Sheets("Sheet1").Range("I10").Value = TextBox17.Value
        Sheets("Sheet1").Range("J10").Value = TextBox18.Value
        Sheets("Sheet1").Range("I11").Value = TextBox19.Value
        Sheets("Sheet1").Range("J11").Value = TextBox20.Value
    End If
    
    'Checkbox3
    If CheckBox3.Value Then
        Sheets("Sheet1").Range("M7").Value = TextBox21.Value
        Sheets("Sheet1").Range("N7").Value = TextBox22.Value
        Sheets("Sheet1").Range("M8").Value = TextBox23.Value
        Sheets("Sheet1").Range("N8").Value = TextBox24.Value
        Sheets("Sheet1").Range("M9").Value = TextBox25.Value
        Sheets("Sheet1").Range("N9").Value = TextBox26.Value
        Sheets("Sheet1").Range("M10").Value = TextBox27.Value
        Sheets("Sheet1").Range("N10").Value = TextBox28.Value
        Sheets("Sheet1").Range("M11").Value = TextBox29.Value
        Sheets("Sheet1").Range("N11").Value = TextBox30.Value
    End If
    
    End Sub

    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:22 AM.

  14. #14
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    I do not know, you can try this
    Private Sub CommandButton1_Click()
    With Sheets("Sheet1")
    'Checkbox1
    If CheckBox1.Value Then
        .Range("E7").Value = TextBox1.Value
        .Range("F7").Value = TextBox2.Value
        .Range("E8").Value = TextBox3.Value
        .Range("F8").Value = TextBox4.Value
        .Range("E9").Value = TextBox5.Value
        .Range("F9").Value = TextBox6.Value
        .Range("E10").Value = TextBox7.Value
        .Range("F10").Value = TextBox8.Value
        .Range("E11").Value = TextBox9.Value
        .Range("F11").Value = TextBox10.Value
     End If
    End With
    '
    '
    and if you want to see in the userform yr values try to add in the userform this code
    just try to play with it
    Private Sub UserForm_Activate()
    CheckBox1.Value = 1
    CheckBox2.Value = 1
    TextBox1.Value = [e7] 'it shows the value from cell e7 in textbox1
    TextBox2.Value = [f7]
    End Sub
    '
    '

  15. #15
    Registered User
    Join Date
    06-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: textbox and checkbox

    Thanks! you have been a great help to me!



    Go www.cashcrate.com/3866888 to earn cash online!!!
    Last edited by ngkj; 07-17-2012 at 05:22 AM.

  16. #16
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: textbox and checkbox

    glad to be of help!

+ 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