Consulting

Results 1 to 4 of 4

Thread: VBA FOR INSERTING ROWS

  1. #1

    VBA FOR INSERTING ROWS

    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.

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    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

  3. #3
    Worked perferect!

    Thanks!

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •