If Then to Add Row

  • Thread starter Thread starter bforster1
  • Start date Start date
B

bforster1

I have written the following code to add a row based on the numbe
selected by the user via a spinbutton.

Sub AddRow()
If Sheets("Sheet1").Range("B3").Value = "2" Then Rows("4:10").Selec
Selection.EntireRow.Hidden = True
If Sheets("Sheet1").Range("B3").Value = "1" Then Rows("4:10").Selec
Selection.EntireRow.Hidden = False
End Sub

The function does not work and I would appreciate any assistance.
would also like the code to fire each time the spinbutton is changed.

Thank
 
bforster1,

Your code would only hide and unhide rows, it doesn't insert. Use the macro
recorder and insert a row to get a start on some code.

To have it fire on a spinbutton change, you need to use a spinbutton from
the Control Toolbox - not the Forms toolbar. Then just double-click on the
spinbutton when you are in design mode and insert the code into the module
that appears (it will be the worksheet module for the sheet the button is
in). The code window will look something like this:

Private Sub SpinButton1_Change()

'insert your code here

End Sub

hth,

Doug Glancy
 

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

Back
Top