QP School

Full Version: Insert a new row and fill it with data in VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example:

Sub InsertAndFillRow()
    Rows(2).Insert Shift:=xlDown
    Range("A2").Value = "John"
    Range("B2").Value = 25
    Range("C2").Value = "Sales"
End Sub

Explanation:

The code defines a subroutine named InsertAndFillRow.
Rows(2).Insert Shift:=xlDown inserts a new row at the second row and shifts the existing rows down to make space for the new row.
Range("A2").Value = "John" sets the value "John" in cell A2.
Range("B2").Value = 25 sets the value 25 in cell B2.
Range("C2").Value = "Sales" sets the value "Sales" in cell C2.