I'm trying to see if I can modify these codes for my needs or attempt to replicate it using macro recorder.
Source codes I found:
In my sheet I have columns going from A to BT and ideally the macro above would go into a button placed somewhere on the page.
For the 1st source code I think it actually works pretty well and all I'd change is probably the final line to paste the formulas and formatting. Is the VBA function for this XLPastespecial or something like that?
For the 2nd source code instead of using activecell I think maybe using an actual range would be better however, I'm wondering if I should make A:BT into a named range would save me troubles down the line? Also this one is closer to what I kind of want as it prompts the user for # of rows you want to add but with the current way its written you'd have to be in the row below the last one with all the contents or else it doesn't work which is my understanding on the "ActiveCell" part.
Source codes I found:
Code:
'Original code from http://www.ozgrid.com/forum/showthread.php?t=16543
Sub AddARow()
Dim varUserInput As Variant, RowNum
varUserInput = InputBox("Enter Row Number where you want to add a row:", _
"What Row?")
If varUserInput = "" Then Exit Sub
RowNum = varUserInput
Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
Rows(RowNum - 1 & ":" & RowNum - 1).Copy Range("A" & RowNum)
Range(RowNum & ":" & RowNum).ClearContents
End Sub
'http://www.ozgrid.com/forum/showthread.php?t=16543
Sub InsertRow()
Dim Rng, n As Long, k As Long
Application.ScreenUpdating = False
Rng = InputBox("Enter number of rows required.")
If Rng = "" Then Exit Sub
Range(ActiveCell, ActiveCell.Offset(Val(Rng) - 1, 0)).EntireRow.Insert
'need To know how many formulas To copy down.
'Assumesfrom A over To last entry In row.
k = ActiveCell.Offset(-1, 0).Row
n = Cells(k, 256).End(xlToLeft).Column
Range(Cells(k, 1), Cells(k + Val(Rng), n)).FillDown
End Sub
In my sheet I have columns going from A to BT and ideally the macro above would go into a button placed somewhere on the page.
For the 1st source code I think it actually works pretty well and all I'd change is probably the final line to paste the formulas and formatting. Is the VBA function for this XLPastespecial or something like that?
For the 2nd source code instead of using activecell I think maybe using an actual range would be better however, I'm wondering if I should make A:BT into a named range would save me troubles down the line? Also this one is closer to what I kind of want as it prompts the user for # of rows you want to add but with the current way its written you'd have to be in the row below the last one with all the contents or else it doesn't work which is my understanding on the "ActiveCell" part.
Last edited: