Insert Cells

Tags:  

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




 RSS of this page