PDA

View Full Version : VBA FOR INSERTING ROWS



becky halsey
11-02-2018, 07:48 AM
I need a VBA or a non vba to insert rows before the target row in a workbook. Not all sheets will have the same target row. Any ideas? Thanks in advance.

Logit
11-02-2018, 09:59 AM
.


Option Explicit


Sub AddRow()
Dim ws As Worksheet
Dim rng As Range


'~~> Set this to the relevant worksheet
Set ws = ThisWorkbook.ActiveSheet

With ws
'~~> Set your range
Set rng = .Rows(ActiveCell.Row)


'~~> Insert the range
rng.Offset(0).Insert Shift:=xlDown '<-- NOTE: Change Offset to (1) & xlDown for new row down.
'<-- Note: Change Offset to (0) & xlUp for new row up.
End With
End Sub

becky halsey
11-02-2018, 10:22 AM
Worked perferect!

Thanks!

Logit
11-02-2018, 10:34 AM
.
Welcome.