iWantToLearn
08-30-2014, 12:35 PM
Hi there,
I have problems with dinamycally adding and removing checkboxes.
I have a form and there is a button to add more rows to the table. Every row includes a checkbox too.
So first i add a row, and then add a checkbox to a specified cell in that row.There is a button for removing rows as well (witch should removes checkboxes as well).
My problem is when i ad the checkbox the linked cell property only works for the first one.When i add the second row the linked cell of the firstly added checkbox changes to the one in the new row and the new checkbox has no linked cell. I am adding the stuffs as follows:
---------------------------------------------------
Private Sub addBtn_Click()
Dim y As Integer
y = findFunc("end") // Y define where to insert the new row
Cells(y, 11).EntireRow.Insert
Cells(8, 11).Copy
Cells(y, 11).PasteSpecial xlPasteValidation
Application.CutCopyMode = False
addCb (y)
End Sub
-----------------
Sub addCb(y As String)
Dim shtActive As Worksheet
Set shtActive = ActiveSheet
With shtActive.CheckBoxes
.Add(Range("M" & y).Left, Range("M" & y).Top, Width:=15, Height:=15).Select
Selection.Value = xlOn
Selection.Characters.Text = "%"
.LinkedCell = Selection.TopLeftCell.Address // doesnt work with Address(False, False) neither
End With
End Sub
--------------------------------------------------------------------
I am new to VBA, and i dont even know if its a good way to add checkboxes dinamycally. Any idea why the linked cells move, or what i did wrong?
Thanks for any advices and help:)
br,
Joco
I have problems with dinamycally adding and removing checkboxes.
I have a form and there is a button to add more rows to the table. Every row includes a checkbox too.
So first i add a row, and then add a checkbox to a specified cell in that row.There is a button for removing rows as well (witch should removes checkboxes as well).
My problem is when i ad the checkbox the linked cell property only works for the first one.When i add the second row the linked cell of the firstly added checkbox changes to the one in the new row and the new checkbox has no linked cell. I am adding the stuffs as follows:
---------------------------------------------------
Private Sub addBtn_Click()
Dim y As Integer
y = findFunc("end") // Y define where to insert the new row
Cells(y, 11).EntireRow.Insert
Cells(8, 11).Copy
Cells(y, 11).PasteSpecial xlPasteValidation
Application.CutCopyMode = False
addCb (y)
End Sub
-----------------
Sub addCb(y As String)
Dim shtActive As Worksheet
Set shtActive = ActiveSheet
With shtActive.CheckBoxes
.Add(Range("M" & y).Left, Range("M" & y).Top, Width:=15, Height:=15).Select
Selection.Value = xlOn
Selection.Characters.Text = "%"
.LinkedCell = Selection.TopLeftCell.Address // doesnt work with Address(False, False) neither
End With
End Sub
--------------------------------------------------------------------
I am new to VBA, and i dont even know if its a good way to add checkboxes dinamycally. Any idea why the linked cells move, or what i did wrong?
Thanks for any advices and help:)
br,
Joco