ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Then to Add Row (https://www.excelbanter.com/excel-programming/311762-if-then-add-row.html)

bforster1[_14_]

If Then to Add Row
 

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

--
bforster
-----------------------------------------------------------------------
bforster1's Profile: http://www.excelforum.com/member.php...fo&userid=1177
View this thread: http://www.excelforum.com/showthread.php?threadid=26435


Doug Glancy

If Then to Add Row
 
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

"bforster1" wrote in message
...

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

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

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

Thanks


--
bforster1
------------------------------------------------------------------------
bforster1's Profile:

http://www.excelforum.com/member.php...o&userid=11771
View this thread: http://www.excelforum.com/showthread...hreadid=264351





All times are GMT +1. The time now is 08:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com