Semua Balasan

  • $worksheet.UsedRange.Rows.Count + 1

    Gets the next available row index.

    Use Range.Paste()

    Also we can avoid past using CopyTo.  Copies a range to a range.  It can also copy between sheets and workbooks.

    Paste is mostly obsolete except when copying from non-Excel sources.


    • Diedit oleh jrv Kamis, 10 Mei 2018 19.40
    Kamis, 10 Mei 2018 19.37
  • Please do not post duplicate questions when you are unsatisfied with an answer.

    For critical Excel programming issues you should post in the Excel Developers forum.

    Your code is not pasting into the range end.  You want to target the last row and first column of the target sheet.  The target range should be one cell  - the upper left corner of the desired region.

    $r = $xl.Worksheets[1].Cells.Item($xl.Worksheets[1].UsedRange.Rows.Count+1,1)

    This gets the first cell after the UsedRange and pastes the new data from there.


    Kamis, 17 Mei 2018 16.42