Put a button in a cell
Try this against a copy of your worksheet--just in case:
Option Explicit
Sub AddButtons()
Dim myRng As Range
Dim myCell As Range
Dim wks As Worksheet
Dim myBTN As Button
Set wks = ActiveSheet
With wks
.Buttons.Delete 'remove existing buttons???
Set myRng = .Range("a1:a10")
For Each myCell In myRng.Cells
With myCell
Set myBTN = .Parent.Buttons.Add _
(Height:=.Height, _
Width:=.Width, _
Left:=.Left, _
Top:=.Top)
myBTN.Name = "BTN_" & .Address(0, 0)
myBTN.OnAction = ThisWorkbook.Name & "!myBTNmacro"
myBTN.Caption = "Click Me"
End With
Next myCell
End With
End Sub
Sub myBTNMacro()
Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
With myBTN
.TopLeftCell.EntireRow.Delete
.Delete
End With
End Sub
Christopher Benson-Manica wrote:
Michael Malinsky spoke thus:
Put the button where you want it then, while in design mode, right-click the
button and select Format Control. On the Properties tab, select "Don't move
or size with cells" to cause to button to remain in position regardless of
the adding or deleting of cells.
Hm... I guess my original post wasn't really clear. I need a button
(or something else!) that fits inside a cell completely and deletes
the row it's on (as well as itself) when clicked. It needs to be
inside a cell, because I want one of these for each row on a
worksheet, including rows not currently visible... I appreciate your
help, and I hope I'm being more clear this time. :)
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
--
Dave Peterson
|