I have a table format questionnaire to be filled on Userform. There are some sections that to be answered only by check-boxes.Those check-boxes are exist in both worksheet and userform. When the user click the box in the userform it need to be ticked in worksheet as well(I don't know if it is possible).
You can write some If statements to assign the same value to the worksheet checkbox on the click or change event of the UserForm checkbox.
Something like:
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
ThisWorkbook.Sheets(1).CheckBox1.Value = True
ElseIf Me.CheckBox1.Value = False Then
ThisWorkbook.Sheets(1).CheckBox1.Value = False
End If
End Sub
1) Link your checkboxes on your sheet to a cell (whichever cell, even on another sheet)
2) Here is the code you could alter to your liking. Make sure to use it as a clickevent on your checkboxes on your userform:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then Range("D3").Value = True
If CheckBox1.Value = False Then Range("D3").Value = False
End Sub
3) Outcome will be like:
Related
I used checkboxes, when clicked depending on which checkbox is selected, specific rows unhide.
Code runs fine. Only issue is that code is not triggered by clicking the checkbox but works when I select any cell in the sheet.
Below is some of the code used:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Activate
If Range("C2").Value Or Range("C3").Value Or Range("C4").Value Or Range("C5").Value Or Range("C6").Value Or Range("C7").Value Or Range("C8").Value Or Range("C9").Value Then
Rows("39:52").EntireRow.Hidden = False
Rows("166:169").EntireRow.Hidden = False
Rows("173:175").EntireRow.Hidden = False
Else
Rows("39:52").EntireRow.Hidden = True
Rows("166:169").EntireRow.Hidden = True
Rows("173:175").EntireRow.Hidden = True
End If
End Sub
Because you using event [Worksheet_SelectionChange], so it only run when you change selection cell.
If you want run when you click checkbox, you must write event [click] of checkbox
Ex:
Sub CheckBox1_Click()
End Sub
I am trying to auto select a checkbox if any another checkbox is selected. All this checkboxes are on the same sheet and basically i want check box 7 to tick if checkbox 3,4 or 5 is selected.
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("Start Page").CheckBox3 = True Or Sheets("Start Page").CheckBox4 = True Or
Sheets("Start Page").CheckBox5 = True Then
Sheets("Start Page").CheckBox7 = True
Else
End If
End Sub
Any help would be greatly appreciated.
Even if your checkboxes are linked to a cell (LinkedCell-property), the Worksheet-Change-event is not triggered when you click on a Checkbox.
You need to catch the Click-Event of the checkboxes. For every checkbox, put a Click-event routine into the sheet module. To prevent that the logic if or if not to set the "calculated" checkbox is repeated, let those event handler call a common routine that does the calculation.
Private Sub CheckBox3_Click()
Call SetMyCheckBox
End Sub
Private Sub CheckBox4_Click()
Call SetMyCheckBox
End Sub
Private Sub CheckBox5_Click()
Call SetMyCheckBox
End Sub
Sub SetMyCheckBox()
Me.CheckBox7.Value = Me.CheckBox3.Value Or Me.CheckBox4.Value Or Me.CheckBox5.Value
End Sub
You should, by the way, consider to give your checkboxes more meaningful names.
I have a form control checkbox and the following code to hide and unhide row 10.
It hides but does not unhide.
Sub CheckBox1_Click()
If Range("C84").Value = True Then
Rows("10:10").EntireRow.Hidden = False
Else
Rows("10:10").EntireRow.Hidden = True
End If
End Sub
The code works perfectly.
Furthermore, if the value of cell C84 is not used elsewhere, the same can be obtained without using LinkedCell:
Sub CheckBox1_Click()
Rows("10:10").EntireRow.Hidden = Not CheckBox1
End Sub
For it to unhide c84 value should be false as long as it is true it will be hidden only
I have made a combo box within a userform:
private sub Userform_Activate
cmbLocation.AddItem "Field"
cmbLocation.AddItem "Remote"
cmbLocation.AddItem "Other"
end sub
when a user selects Other I'd like a text box to populate for free form text input. When the user does this, I'd like that text to be the .value that is populating into the worksheet table.
is this even possible?
Create a textbox and set it to .visible = False when the userform is activated. Then using an if statement you can output the data from either the combobox or the textbox.
Private Sub UserForm_Activate()
Me.txtLocation.Visible = False
Me.cmbLocation.AddItem "Field"
Me.cmbLocation.AddItem "Remote"
Me.cmbLocation.AddItem "Other"
End Sub
Private Sub cmbLocation_Change()
If Me.cmbLocation.Value = "Other" Then
Me.txtLocation.Visible = True
Else
Me.txtLocation.Visible = False
End If
End Sub
Private Sub CommandButton1_Click()
If Me.txtLocation.Visible = True Then
ThisWorkbook.Sheet1.Range("A1").Value = Me.txtLocation.Value
Else
Thisworkbook.Sheet1.Range("A1").Value = Me.cmbLocation.Value
End If
End Sub
Modify sheet and range as necessary
I have a form created in excel which has rows [10:48] hidden and I want to make so that when you click a checkbox rows [10:48] are unhidden. I assigned a macro to the checkbox and using this formula:
Private Sub CheckBox45_Click()
If CheckBox45 = True Then
[10:48].EntireRow.Hidden = False
Else: [10:48].EntireRow.Hidden = True
End If
End Sub
When I click the checkbox nothing happen, but when I unhide the rows and click the checkbox it hides the rows. Which makes me think that only one of the actions is working. Is there a way to fix this?
Thanks in advance for the help.
Don't know if this matters but the form checkbox is in column D row 6
This assumes you are hiding/unhiding rows on Sheet 1 and the checkbox belongs to sheet 1 of the workbook, then:
Private Sub CheckBox30_Click()
If ThisWorkbook.Sheets(1).CheckBoxes("Check Box 30").Value = 1 Then
ThisWorkbook.Sheets(1).Rows("10:48").Hidden = true
Else
ThisWorkbook.Sheets(1).Rows("10:48").Hidden = false
End If
End Sub
Here is another approach.
The statement ws.CheckBoxes("Check Box 30") = 1 will either return TRUE or FALSE which will either hide, or unhide, your target rows.
Private Sub CheckBox30_Click()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1")
ws.Range("A10:A48").EntireRow.Hidden = ws.CheckBoxes("Check Box 30") = 1
End Sub