Issue : Copy Paste Excel data from one worksheet to another in same file Using invoke code

Hi All,
I am trying to copy and paste the whole data irrespective of range from one worksheet to another worksheet in same excel file.
Below is the code

appXL = New Microsoft.Office.Interop.Excel.ApplicationClass
appXL.Visible = True

wbSource = appXL.Workbooks.Open("C:\Users\Administrator\Desktop\New folder\" & "Copy.xlsx")

wksSource =CType(wbSource.Worksheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)

wksDest = CType(wbSource.Worksheets("Sheet2"), Microsoft.Office.Interop.Excel.Worksheet)

wksDest.UsedRange.Value=wksSource.UsedRange.Value 

With this , only first cell is being copied.I need to copy the whole sheet.

Could you please help me out with what I am missing here?
Thank You

Hi Abhishek,

You are just assigning the value of the Range property from one sheet to other and you have not specified the Complete range, due to which only first cell is getting copied.

If you use copy method of the worksheet object then you will be able to move data from one sheet to other.

Thanks,
Asish

hi @asishkumar . Thank you , yes i had already tried searching for the copy function of worksheet object , but copy function was not available under list of functions of worksheet object.

Do we need add any references externally for this copy function ?
Note : I have already added Excel reference.(Microsoft.Office.Interop.Excel)

Thank You