Hello,
I have this code to create checkboxes,
Can you please help me creating multiple checkboxes in front of multiple rows (in range C), and linking each checkbox to a cell of that same row (Cells in range B), and applying a condition to change the value of that cell (which is in range C) according to its checkbox state (On or Off)
What I want is (as alogirthm or simple vba explanation to try and make it more clear maybe):
The Code I have:
I have this code to create checkboxes,
Can you please help me creating multiple checkboxes in front of multiple rows (in range C), and linking each checkbox to a cell of that same row (Cells in range B), and applying a condition to change the value of that cell (which is in range C) according to its checkbox state (On or Off)
What I want is (as alogirthm or simple vba explanation to try and make it more clear maybe):
VBA Code:
[COLOR=rgb(65, 168, 95)]For Each Row in Range("A")
If Not IsEmpty(Cell(Range("C"))) Then
Cell(Range("C")).ClearContents
ElseIf IsEmpty(Cell(Range("C"))) Then
If CheckBox = True Then
Cell.Range("B").Value = 2
If CheckBox = False Then
Cell.Range("B").Value = 1
End If[/COLOR]
The Code I have:
VBA Code:
Sub AddCheckBoxes()
Dim i, LRow As Single
Dim chkbx As CheckBox
Dim MyLeft, MyTop, MyHeight, MyWidth As Double
Application.ScreenUpdating = False
LRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LRow
If Cells(i, "A").Value <> "" Then
If Not IsEmpty(Cells(i, "C")) Then
Cells(i, "C").ClearContents
ElseIf IsEmpty(Cells(i, "C")) Then
MyLeft = Cells(i, "C").Left
MyTop = Cells(i, "C").Top
MyHeight = Cells(i, "C").Height
MyWidth = Cells(i, "C").Width
With ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight)
.Caption = ""
.Value = xlOff
.LinkedCell = "B" & LRow
.Display3DShading = False
End With
End If
End If
If ActiveSheet.CheckBoxes("CheckBox1").Value = True Then
Range("B2").Value = 2
ElseIf ActiveSheet.CheckBoxes("CheckBox1").Value = False Then
Range("B2").Value = 1
End If
Next i
Application.ScreenUpdating = True
End Sub