Add a row using a macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have any idea how to add a specified number of rows based on user input using a macro

Ex. In cell C7 user is prompted to enter the number of rows to be added. The user types in 3. This would then input three rows below Row 7 (ie. adding three rows between current row 7 and current row 8)
 
Here's a macro to do it

Sub AddRows()
Dim num

num = InputBox("Please supply number of rows")
If num <> "" Then
If IsNumeric(num) Then
ActiveCell.Offset(1, 0).Resize(num, 1).EntireRow.Insert
End If
End If

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

S Ruhmann said:
Does anyone have any idea how to add a specified number of rows based on user input using a macro?

Ex. In cell C7 user is prompted to enter the number of rows to be added.
The user types in 3. This would then input three rows below Row 7 (ie.
adding three rows between current row 7 and current row 8).
 
Hi
try
Sub insert_rows()
Dim row_height As Long

row_height = ActiveSheet.Range("C7")
ActiveSheet.Cells(8, 1).Resize(row_height, 1).EntireRow.Insert

End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

S Ruhmann said:
Does anyone have any idea how to add a specified number of rows based on user input using a macro?

Ex. In cell C7 user is prompted to enter the number of rows to be
added. The user types in 3. This would then input three rows below
Row 7 (ie. adding three rows between current row 7 and current row 8).
 
Back
Top