View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
AndrewSiffert AndrewSiffert is offline
external usenet poster
 
Posts: 2
Default Deleting Checkbox Object in Cell

Hello Again, I am new with VBA and I apricate anyone who offers help.
Lets first explain what I am trying to do:

Set up Excel:
In excel sheet1 create four check boxes place them in "E10", "E11",
"E12", "E13". These check boxes have no text, are in 3D and link to "G10",
"G11","G12", "G13" and check the box to make these cells read false.

The problem:
On row 12 incert a row
The problem is when I do this the link moves too the checked cell, but the
check box does not move down with that row. So I want to move the check box
down to the row with the linked cell. So, the Checkbox in "E12" needs to be
moved to "E13".


What can I write to either move this checkbox down a row.

What I tired is to create a new check box knowing wheather it is true or
false and than delete the old one in "E12". But I can't seem to get that to
work.

Current Code
Sub Trial1()
'Create Checkbox
Range("E13").Select
Dim A As String
A = Range("G13")
If A = False Then
Dim c As Range, myRange As Range
Set myRange = Selection
For Each c In myRange.Cells
ActiveSheet.CheckBoxes.Add(c.Left, c.Top, c.Width, c.Height).Select
With Selection
.Value = xlOff
.LinkedCell = "g13"
.Display3DShading = True
.Characters.Text = ""
.Name = c.Address
End With
c.Select
Next
End If
'Delete old checkbox
''''Sample Code'''
Dim Cbox As CheckBox
Dim Rng As Range

Set Rng = Range("E12") '<<==== CHANGE

For Each Cbox In ActiveSheet.CheckBoxes
If Not Intersect(Cbox.TopLeftCell, Rng) Is Nothing Then
Cbox.Delete
End If
Next Cbox
End sub


"Norman Jones" wrote:

Hi Andrew,

More flexible would be:

'=============
Sub TestB()
Dim Cbox As CheckBox
Dim Rng As Range

Set Rng = Range("A8, C8") '<<==== CHANGE

For Each Cbox In ActiveSheet.CheckBoxes
If Not Intersect(Cbox.TopLeftCell, Rng) Is Nothing Then
Cbox.Delete
End If
Next Cbox

End Sub
'<<=============

---
Regards,
Norman


"AndrewSiffert" wrote in message
...
Hello,
I have not problem creating a checkbox with in a cell. However when it
come
time to delete the checkbox I can't seem to select the object. Note, the
sheet has several checkboxes and deleting them by name will not work. I
need
to reference a cell to delete the checkbox.

ActiveSheet.CheckBoxes.Delete

This works great for all cells but how about if I just want to delete one
checkbox in an selected cell.

Thanks,
Andy