macro that copies controls
Melanie,
I tried the macro record approach and the chk boxes were copied/pasted
when I ran it, however, rather than pasting the chkbox in my new row
it was pasted over the top of the existing checkbox. Try deleting or
moving the original textbox - I'm guessing you'll find another one
underneath.
You may find the following interesting. It inserts a checkbox in
column "H" on the current row when the user types something in column
3 of that row.
Depending how your copy/paste macro looks like you should be able to
modify this to suit. The key thing is to set the top of the checkbox
object to the top of the row that you are in.
If you have difficulties please post back your code and I'll see what
I can do.
Good luck,
Andrew
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range
Dim obj As Object
If Target.Count 1 Then Exit Sub
If Target.Column = 3 Then
If IsEmpty(Target) Then Exit Sub
Set rng = Cells(Target.Row, "H")
' Check if there is already a checkbox
For Each obj In ActiveSheet.OLEObjects
'If TypeOf obj.Object Is MSForms.CheckBox Then
If obj.TopLeftCell.Address = rng.Address Then
Exit Sub
End If
'End If
Next
With ActiveSheet.OLEObjects.Add( _
ClassType:="Forms.CheckBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=rng.Left + rng.Width / 2 - 10, _
Top:=rng.Top, _
Width:=rng.Width, _
Height:=rng.Height)
.Object.Caption = ""
'.LinkedCell = rng.Address
.Object.Value = False
End With
Application.ScreenUpdating = True
End If
End Sub
"Melanie" wrote in message ...
I have created a macro to copy and paste certain rows in a worksheet. These rows contain check boxes. I would like the macro to also copy the check boxes.
When I create the macro to copy and paste the rows, the check boxes are also copied. However, when I run the macro, the check boxes are not created(?).
Is this possible? Any ideas? Anyone? Anyone?
|