Excel- command button- click event needs to work

D

Dawn Murray

Hi,

I have created a command button in excel to insert new row.

My problem is I cannot get it to insert new row...I even tried a macro--but
insert row is greyed out in the insert menu, so I cannot go that route. I
need someone to help me with the code for getting excel to insert new row
when the user clicks the command button.

Thanks in advance for your help.

Dawn
 
N

Nick Hodge

Dawn

Is the command button from the Control Toolbox (ActiveX) or Forms Toolbox?

If it is from the Control Toolbox then if it is called CommandButton1 then
the click event will look like so. It inserts a row at the activecell (For
demo only). The TakeFocusOnClick can be set at design time, but it ensures
the activecell isn't lost when you click the button.

Private Sub CommandButton1_Click()
CommandButton1.TakeFocusOnClick = False
ActiveCell.Rows.Insert
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
 
Top