Tuesday, February 15, 2011

Copy Specifc Data from One Excel to Other

' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If
On Error GoTo 0

'Create an object for Excel file

Set xlBook = objExcel.Workbooks.Open("C:\Documents and Settings\deepakpe\Desktop\Mine_doc\new.xlsx")
Set xlSheet = xlBook.Worksheets(1)


' Select the range of data to be copy
objexcel.Range("D1:D46").Copy
set xlSheet = xlBook.Worksheets("Sheet2")
' Select the range where we want to copy
objexcel.Range("C3").Select
objexcel.Range("c3").Copy


objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

'Release an object

Set xlBook = Nothing
Set xlSheet = Nothing

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons