Copy paste entire row with insert shift down in excel

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Korhan Tezel Korhan Tezel 1 year, 1 month ago.

  • Author
  • #29705
    Profile photo of Korhan Tezel
    Korhan Tezel

    Hello folks,

    I am trying to write a PS script where it will select entire row or a range and then insert the selection to row below.
    $selection = $sourceWorkbook.Worksheets.item(1).Range("A125:E125").EntireRow.Select

    This code is giving me the error below:
    Method invocation failed because [System.Management.Automation.PSMethod] doesn't contain a method named 'insert'

  • #29709
    Profile photo of Korhan Tezel
    Korhan Tezel

    Ok. If anyone interested, below code works when I run it with PowerShell ISE (x86); however, when I run it via Run Command it won't work. This is the part that doesn't work:
    # xlDirection is the parent containing constants related to Direction
    $xlDirection = "" -as [type]
    $xlDown = $xlDirection::xlDown
    ....(There are couple of statements in between)
    $selection = $sourceWorkbook.Worksheets.item(1).Range("A125:E125")

    The error reads as below:
    Exception calling "Insert" with "1" argument(s): "Insert method of Range class failed"

    I don't get this error with ISE. It runs smoothly and everything works perfect.

You must be logged in to reply to this topic.