View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
GS[_5_] GS[_5_] is offline
external usenet poster
 
Posts: 226
Default Macro: insert rows anywhere in the sheet

Here's a generic proc you can modify to suit or keep as a reusable
utility:

Public Sub InsertBlankRows(Optional Position As String)
' Inserts a specified number of rows at the location specified.
' If the Position arg is not used then the default is ActiveCell.Row.

Dim vRows As Variant, lPos As Long
Const sMsg As String = "Enter the number of rows to insert."

'Evaluate user input
On Error Resume Next
vRows = InputBox(Prompt:=sMsg, Default:=1)
If vRows = "" Then Exit Sub '//user cancels
If Not Err = 0 Or _
Not IsNumeric(vRows) Or _
Not vRows = 1 Then Exit Sub

'Get the position to insert
lPos = ActiveCell.Row
If Position = "Below" Then lPos = lPos + 1

'Insert the rows
Cells(lPos, 1).Resize(vRows).Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc