Need to modify VBA code

Earth_shaker

New Member
Joined
Jan 7, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Looking to remove ActiveCell and have it use a specific cell "A4" as the insert location.
Also, in Column A of my table I have a simple Formula =ROW(A1) that gives the result 1. When I insert the rows, it makes them all =ROW(A2) with the result of 2,2,2,2, instead of ...A2, A3, A4, resulting in 2,3,4,etc.

"Sub InsertRows()

Dim i As Integer, j As Integer
ActiveCell.EntireRow.Select
On Error GoTo last
i = InputBox("Enter the number of Holes in Shot", "Complete")
For j = 1 To i - 1
Selection.Insert Shift:=xltodown, copyOrigin:=xlFormatFromLeftOrAbove
Next j
last:
Exit Sub

End Sub"
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about:

VBA Code:
Sub InsertRows()
'
    Dim i   As Long, j  As Long
'
    i = InputBox("Enter the number of Holes in Shot", "Complete")
'
    For j = 1 To i - 1
        Range("A4").EntireRow.Insert Shift:=xltodown, copyOrigin:=xlFormatFromLeftOrAbove
        Range("A4").Formula = "=Row()"
    Next j
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,728
Messages
6,174,150
Members
452,548
Latest member
Enice Anaelle

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