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 sheet protected?

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
D

Dawn Murray

Hi,

No it is not protected


Nick Hodge said:
Dawn

Is the sheet protected?

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top