[b]Insert new row??[/b]

PaulDReed

Board Regular
Joined
Apr 19, 2003
Messages
50
Help!!
I am writing a sheet where different users will enter data in rows,
which include validation features and also default data in some of the
cells.
I want to create a macro, operated by a button, where a user can
insert a 'new' row (which contains validation and default data), at
position row 2 (so the new row is directly below the headings.
I have tried (and failed miserably) but then, I am a newbie!
I have tried creating a dummy hidden row at row 2, but as the list is
filtered, I just get error messages.

Thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Code:
Sub AddRowAt2()

  Range("A2").EntireRow.Insert
  Range("A3").EntireRow.Copy
  Range("A2").EntireRow.PasteSpecial xlPasteFormats
  Application.CutCopyMode = False
  Range("A2").Select

End Sub

This should do it for you!
 
Upvote 0
LT, that won't give him the default data/formulas he needs. I like the idea of a hidden dummy row just below the headers. Just have to include in the macro to unhide, copy and paste and then hide again. Any reason this wouldn't work?
 
Upvote 0
For instance, assuming row 1 is your headers, row 2 is your dummy row and is hidden, try this:


Code:
Sub Macro1()
    Rows("3:3").Select
    Selection.Insert Shift:=xlDown
    Rows("1:3").Select
    Selection.EntireRow.Hidden = False
    Rows("2:2").Select
    Selection.Copy
    Rows("3:3").Select
    ActiveSheet.Paste
    Rows("2:2").Select
    Selection.EntireRow.Hidden = True
End Sub
 
Upvote 0
Barry

You're correct, the code that you wrote differs from mine, because yours unhides/hides the dummy row, whereas mine did not, which makes a significant difference.

By adding a few other bits, the macro works great.

Thanks
 
Upvote 0

Forum statistics

Threads
1,221,695
Messages
6,161,361
Members
451,699
Latest member
sfairbro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top