Hi there,
I'm using two macros (suggested by davesexcel in the thread "need to insert row with button", thanks) to create a button that when clicked, inserts a row... Here they are:
Sub CreateButtonsInA_Selection()
'this createts a button and assigns the InsertRow macro to it in a selection
For Each Cell In Selection.Cells
With ActiveSheet.Buttons
.Add Cell.Left, Cell.Top, Cell.Width, Cell.Height
.OnAction = "InsertRow"
End With
Next Cell
End Sub
Sub InsertRow()
'this inserts a row where the button is clicked.
Dim r As Range
Set r = ActiveSheet.Buttons(Application.Caller).TopLeftCell
r.EntireRow.Insert
End Sub
However, when clicking the button, I get this error message: "Cannot run the macro "blablabla". The macro may not be available in this workbook or all macros may be disabled." Any ideas? Some additional info:
- My file is a .xls, and I'm working in Excel 2010.
- I've checked under "developer > code > macro security > macro settings" and both "Enable all macros (not recommended...)" and "Trust acces to the VBA project object model" are selected.
- Under "developer > visual basic", when I select ThisWorkbook in the Project pane, I see the codes so the macros seem to be "in the file".
Also, I have some additional questions:
- Will the inserted row be above or below the row in which the button is? I want it to be above...
- Will the inserted row contain the same formulas and have the same formatting (the cells containing the formulas should be locked) as the row in which the button is? If not, is there a way to get what Iwant?
- I want the buttons to read "add row", is there a line I can add to the macro code so as to make this happen?
Many thanks in advance!
Bookmarks