Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell - copy data from excel

$
0
0

Hello,

i have a question, i am building a powershell but i am not very good at it :)

what i am trying to do is copy from a excel file a single cell (C2) to another excel file cell. this part work like a charm.. but when i run the .ps1 again it overwrites the data. i would like it to copy it to the next cell where there is no data inside.

this is powershell:

$excel=new-object -comobject excel.application;
$excel.visible=$true;
$SourceWorkBook=$Excel.Workbooks.open("G:\Book1.xlsx");
$TargetWorkBook=$excel.workBooks.open("c:\Server List.xlsx");
$SourceWorkBook.WorkSheets.item(1).activate();
$SourceRange1=$SourceWorkBook.WorkSheets.item(1).range("D2");
$SourceRange1.copy() | out-null;
$TargetWorkBook.WorkSheets.item(1).activate();
$TargetRange1=$TargetWorkBook.WorkSheets.item(1).range("B19");
$TargetWorkBook.ActiveSheet.Paste($TargetRange1);

 

please help


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>