Modify Code to Add Line Below Instead of above

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
I have the code below that adds a line above the active A cell. Is there a way to change this so it adds the line below the active A cell?

Code:
Sub insertRevBetween()
ActiveSheet.Unprotect
   Dim iCountRows As Integer
   Dim Rng As Range
   
   iCountRows = 1
   
   'Error Handling
   If iCountRows <= 0 Then Exit Sub
   
   If ActiveCell.Row < 9 Then
      MsgBox "You Cannot Insert Rows Before Line 9!"
      Exit Sub
   End If
   
   Set Rng = Range("A" & ActiveCell.Row)
   Rng.Resize(iCountRows, 37).EntireRow.Insert
   Set Rng = Range("A" & Rng.Row - iCountRows).Resize(iCountRows, 37)
   With Rng
      .Borders.Weight = xlThin
      '.Borders(xlEdgeBottom).Weight = xlMedium
      .Borders(xlEdgeRight).Weight = xlMedium
      .Borders(xlEdgeLeft).Weight = xlMedium
      '.Borders(xlEdgeTop).Weight = xlThin
   End With
          
   Range("B" & ActiveCell.Row - 1).Select
   ActiveCell.Copy
   Range("B" & ActiveCell.Row + 1).Select
   ActiveCell.PasteSpecial xlPasteValues
       
   Range("Ai" & ActiveCell.Row - 1).Copy
   Range("Ai" & ActiveCell.Row).PasteSpecial Paste:=xlPasteFormulas
   Range("B" & ActiveCell.Row).Select
       
ActiveSheet.Protect
     
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
.
This inserts new row down one :

Code:
Option Explicit


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


    '~~> Set this to the relevant worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")        '<-- NOTE: Insert Sheet name here.


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


        '~~> Copy the range
        'rng.Copy                               '<--  NOTE: Copies content of row the cursor is in and pastes to the new row


        '~~> Insert the range
        rng.Offset(1).Insert Shift:=xlDown       '<--  NOTE: Change Offset to (1) & xlDown for new row down.
                                                '<--  Note: Change Offset to (0) & xlUp for new row up.
        '~~> Clear the clipboard. More importantly remove the
        '~~> ant like borders
        Application.CutCopyMode = False
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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