Tuesday, October 13, 2009

Insert rows by macros/Formulas

http://www.mrexcel.com/archive/VBA/193.html

http://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm

******************************************
Sub InsertRow()
Dim Rng
Rng = InputBox("Enter number of rows required.")
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(Rng - 1, 0)).Select
Selection.EntireRow.Insert
End Sub

******************************************
Sub Insert_6_rows()

' Written by Barrie Davidson
Range("A1").Select
Do Until Selection.Value = ""
ActiveCell.Offset(1, 0).Range("A1:A6").Select
Selection.Insert Shift:=xlDown
ActiveCell.Offset(6, 0).Select
Loop
Range("A1").Select
End Sub

******************************************

this code will allow you to specify the number of rows to insert (more versatile).

Sub Insert_rows()
' Written by Barrie Davidson
Dim insertNumber As Integer
On Error Resume Next
Range("A1").Select
insertNumber = CInt(InputBox("Enter number of rows to insert"))
If insertNumber <= 0 Then MsgBox ("Invalid Number Entered") Exit Sub End If Do Until Selection.Value = "" ActiveCell.Offset(1, 0).Range("A1:A" & insertNumber).Select Selection.Insert Shift:=xlDown ActiveCell.Offset(insertNumber, 0).Select Loop Range("A1").Select End Sub



No comments:

Post a Comment