Share via

Using control button to add rows to specific range of cells

Anonymous
2019-07-16T16:41:29+00:00

Hello all,

I have a section in my sheet for the user to add product descriptions. The range of cells is E25 to H25 (header) E26 to H25 (first line of data). 

There is data adjacent to the range so I need to shift the cells down and not insert an entire row.  I found the add a row code on the net and a line of code that is supposed to shift the cells down that I have integrated into the code.

This is the code I have been trying but excel is still adding a complete row.  Can you please suggest/specify the proper VBA code to shift the cell range down without adding an entire row?

Thanks,

Rob

Sub addNewRow()

    ' Do not insert a row before the first row.

    Dim iTopRow As Integer

    iTopRow = 1

    If (ActiveCell.Row > iTopRow) Then

        ' Get the active row number.

        Dim rowNum As Integer

        rowNum = ActiveCell.Row

        Rows(27).Insert shift:=xlShiftDown       ' Insert a new row.

        ' Change the Codes (in first column).

        Cells(ActiveCell.Row, 1) = rowNum - 1       ' For the active cells.

        Dim iTotalRows As Integer   ' Get the total used range rows.

        iTotalRows = ActiveSheet.UsedRange.Rows.Count

        Dim iRows As Integer

        For iRows = rowNum + 1 To iTotalRows

            Cells(iRows, 1) = iRows - 1

        Next iRows

    End If

End Sub

[Moved from Office/Excel/Windows 10/Office 365 for business]

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2019-07-16T17:07:20+00:00

    To:  Rob

    Re:  inserting specific cells

    Try...    Range(Cells(27, 5), Cells(27, 8)).Insert shift:=xlShiftDown

    '---

    Excel workbooks and add-ins

    Download from MediaFire...

    http://www.mediafire.com/folder/lto3hbhyq0hcf/Documents

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-07-16T17:32:00+00:00

    Worked perfectly...thanks!!!!

    Was this answer helpful?

    0 comments No comments