Code on button how?

P

Pieter geerts

I want the following code attach to a commandbutton.

Sub Rij_Invoegen()
ActiveCell.Offset(1, 0).EntireRow.Insert
End Sub

I wont get it working. I want to insert a row under the row i select.
 
D

Dave Peterson

If you use a commandbutton (a commandbutton is from the control toolbox
toolbar), just double click on it and you'll see where the code goes. You'll
just copy|paste that single line--it'll already have the name of the sub and the
End sub line.

If you used a button from the Forms toolbar, you could put your code in a
General module--not behind the worksheet, not behind ThisWorkbook and then
rightclick on that button and choose assign macro.

If you're gonna use this same code for buttons on lots of worksheets, I'd use
the forms button. Each of these forms button can have the same macro assigned
to it.

With commandbuttons, you'll be duplicating the code for each button.
 

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