I have a VBA code that checks/unchecks all checkboxes. However I want the code to check/uncheck only the checkboxes that don't a have 'False' written in them in column E5:E150.
Any help would be appreciated, here is my code :
Sub SelectAllSubSector()
Dim cBoxSector As CheckBox
For Each cBoxSector In Worksheets("Input attractivite").CheckBoxes
If Not Intersect(cBoxSector.TopLeftCell, Range("C5:C150")) Is Nothing Then
If cBoxSector.Name <> ActiveSheet.CheckBoxes("Check Box 3").Name Then
cBoxSector.Value = ActiveSheet.CheckBoxes("Check Box 3").Value
End If
End If
Next cBoxSector
End Sub
Related
Hi I am trying to get the following Macro to work when the checkbox on the userform is not selected. The macro works fine when the checkbox is selected. But when I unselect the checkbox it does not change the value of "E38" to ""
I am also looking for a way for the Checkbox to remain selected once I unload the userform
Private Sub CheckBox_AddBDetails_Click()
If CheckBox_AddBDetails = True Then
Worksheets("Schedule of Supports").Range("E38").Value = TextBox_Name.Value
Else
Worksheets("Schedule of Supports").Range("E38").Value = ""
End If
End Sub
Sub Makro1()
If ActiveSheet.Shapes("Kontrollkästchen 2").ControlFormat.Value = 1 Then
Application.DisplayAlerts = False
Worksheets("Sheet2").Delete
Application.DisplayAlerts = True
End If
End Sub
I just have no idea what i am doing wrong. I have a format control checkbox in Sheet 1 ( I don't want to use ActiveX). Then i have a button linked to Makro1. When i click the button i want the makro to check if the checkbox is clicked and if that is the case, delte Worksheet "Sheet2".
I would be very happy if someone could help me as im not very familiar with makros.
Thanks in advance
You can do it, but the correct VBA code is:
Sub Makro1()
If ActiveSheet.Shapes("Kontrollkästchen 2").OLEFormat.Object.Value = 1 Then
Application.DisplayAlerts = False
Worksheets("Sheet2").Delete
Application.DisplayAlerts = True
End If
End Sub
I have an Excel sheet "TestSheet", and a user form frmTestForm, with an option button named OptionButton1. I added the button manually from the editor, so I believe it is a Form Controls option button. I want to turn on (meaning show as selected) the option button based on the value of cell C2 in sheet "TestSheet".
Sub Test_Form()
Worksheets("TestSheet").Activate
Dim OptionButton1 As OptionButton
Dim myopt As OptionButton
Set myopt = OptionButton1
With frmTest_Form
If Range("C2").Value = 5 Then
OptionButton1.Value = True 'Errors here
End If
End With
frmTest_Form.Show
End Sub
The error message is "Object variable or With lock not set", which I believe indicates the option button is not properly defined, but I don't know how to fix it. Thanks in advance for your help.
I have edited the code to reflect both comments. I still have the sane error message, "Object variable or With lock not set" in the line OptionButton1.Value = True. Thanks again for your help.
Got it to work! Changed code as follows:
Sub Test_Form()
Dim OptionButton1 As Variant
Set OptionButton1 = frmTest_Form.OptionButton1
If Range("C2").Value = 5 Then
OptionButton1.Value = True
End If
frmTest_Form.Show
End Sub
Thanks for your help!
I have built a simple UserForm with a Combobox to delete rows by name.
I have populated the Combobox rowsource using a macro to build a
named range called "Combo_List". I statically inserted that into the
rowsource attribute (meaning, I did not do that with code).
Also on the UserForm is a Checkbox that I want to use for confirmation purposes.
Once they select the username from the list, they need to put a check in the Checkbox and THEN they can click the Delete button.
I have no clue how to write the code that validates the Checkbox and then deletes the selected row.
If it helps, here's the code to build the named range and then show the UserForm:
Sub RecordDelete()
Dim LastRow As Long
ActiveSheet.Select
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
Range("B3:B" & LastRow).Name = "Combo_List"
frmDeleteData.Show
End Sub
The checkbox is just named 'checkbox1'. Any help?
One way to do this is
Set the default property for Enabled for your delete CommandButton to False in design mode
Add code to the CheckBox that enables the CommandButtonwhen the Checkbox is ticked
Add code to the delete CommandButton to delete the entire row
code
Private Sub CheckBox1_Click()
CommandButton1.Enabled = CheckBox1.Value
End Sub
Private Sub CommandButton1_Click()
Dim rng1 As Range
If Me.CheckBox1 Then
Set rng1 = Range("Combo_List").Find(Me.ComboBox1.Value, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
rng1.EntireRow.Delete
Else
MsgBox Me.ComboBox1.Value & "not found"
End If
Else
`redundant if button is disabled
MsgBox "Checkbox not checked!", vbCritical
End If
End Sub
I have a list in excel with an autofilter and where every row has a checkbox.
I have made a button with a macro to select all the checkboxes. This works fine. But when I filter my rows my 'select all' has to select only the visible checkboxes.
With my code it still selects all the checkboxes. Has anybody an idea to solve this?
My code:
Sub SelectAll()
Dim chk As CheckBox
If Worksheets("Summary").FilterMode = True Then
MsgBox "Filter mode is on"
Else
MsgBox "Filter mode is off"
For Each chk In Worksheets("Summary").CheckBoxes
chk.Value = Checked
Next
End If
End Sub
Thanks in advance
I'm taking it that your checkboxes are being hidden by the filtering.
This might help, inside your loop:
Dim chkRng As Range
Set chkRng = chk.TopLeftCell
Let addr = chkRng.Address ' for debugging to verify the cell the checkbox is associated with
Dim visr As Range
Set visr = chkRng.SpecialCells(xlCellTypeVisible)
Set ans = Intersect(visr, chkRng)
If Not ans Is Nothing Then
MsgBox ("visible")
End If