Home / User Contributed Macros / Insert Cells

Insert Cells


Use the following macro to insert the selected cells and move the existing cells towards down.
Public Sub insertSelectedCells()
 Selection.Insert shift:=xlDown
End Sub
Use the following macro to insert the selected cells and move the existing cell towards right.
Public Sub insertSelectedCells()
 Selection.Insert shift:=xlShiftToRight
End Sub

Use the following macros to copy the selected cells and paste into the selected range by inserting new cells.
Dim copyRange As Range

Sub copyCells()
Set copyRange = Selection
End Sub

Sub insertCopiedCells()
Dim selAdr As String
selAdr = Selection.Address
ActiveSheet.Range(copyRange.Address).Copy
If copyRange.Rows.Count=Selection.Rows.count And copyRange.Columns.count = Selection.Columns.count Then
Selection.Insert shift:=xlDown
ActiveSheet.Paste Destination:=Range(selAdr)
Else
Msgbox "The content copied is bigger than the range selected."
End If
End Sub


    ilumshem  06 Jun 2010 
    Re: your 3rd set "seems awkward"

    you should let anyone interested know how to use your set of procedures (macros), but since you didn't I'll try.

    1-select the cell OR range (group of contiguous cells) that contain what you would like to insert at a different position in your spreadsheet. RUN "copyCells" (the first macro in the group)

    2-go to where you want to insert the above mentioned data, and run "insertCopiedCells" the second macro.


    now, why bother with the first macro why not a regular copy OR ctrl+C ?



     RSS of this page