@BetT ,
We are mainly responsible for general issues of Office desktop applications, but your needs focus more on code, I would remove the tag of "office-excel-itpro".
Thanks for your understanding.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to copy some data from File1 excel file to File2 excel file. However File2 excel file already contains some data in that sheet. I don't want my paste operation to overwrite the already existing data on File2. I want to find the last empty range in File2 which I can use in the paste function. However I cannot find the last empty range in File2. So far I have the below code:`
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $true
$wb1 = $xl.Workbooks.Open($file)
$wb2 = $xl.Workbooks.Open($secfile)
$w1 = $wb1.Worksheets.Item(1)
$w2 = $wb2.Worksheets.Item(5)
$ud1 = $w1.UsedRange
$ud1.Copy()
$w2.paste()
I have to the same operation on 5000 sheets so looking to do in using a script.
@BetT ,
We are mainly responsible for general issues of Office desktop applications, but your needs focus more on code, I would remove the tag of "office-excel-itpro".
Thanks for your understanding.
Hi,
You could select a cell before pasting. For example, to paste right to the used range, it could be like this
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $true
$wb1 = $xl.Workbooks.Open($file)
$wb2 = $xl.Workbooks.Open($secfile)
$w1 = $wb1.Worksheets.Item(1)
$w2 = $wb2.Worksheets.Item(5)
$ud1 = $w1.UsedRange
$w2LastColumn = $w2.UsedRange.Columns.Count
$ud1.Copy()
$w2.Cells(1, $w2LastColumn+1).select()
$w2.paste()
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.