• Register
Win an IPAD!!! Checkout this page!
x

Copy data from one sheet to another sheet in Excel

+1 vote

Below code is used to copy data from one sheet(sheet1) to another sheet(sheet2) in Excel.

Function CopySheet(Source,Target,FilePath)
'Option Explicit
'Objects Decleration
Dim objExcel,objWorkbookReque,objWorkbookAccep,objWorksheetReque,objWorksheetAccep,temp,xlValues,Paste
'Below code is used to copy the data from Global sheet to Accept sheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbookReque= objExcel.Workbooks.Open(FilePath)
'Below code is used to Rename the Sheet1 sheet to "Source" and Add the sheet name "Target"
objExcel.ActiveWorkbook.Worksheets.Add
objExcel.Sheets(1).Name = Source
objExcel.Sheets(2).Name = Target
'Below code is used to copy the data in Request sheet to Accept sheet
Set objWorksheetReque= objWorkbookReque.Worksheets(Source)
Set objWorksheetAccep= objWorkbookReque.Worksheets(Target)
objWorkbookReque.Worksheets(Source).UsedRange.Copy
objWorkbookReque.Worksheets(Target).Range("A1").PasteSpecial Paste =xlValues
If Not objWorkbookReque Is Nothing Then 
With objWorkbookReque 
.Save 
.Close 
End With 
End If 
If Not objExcel Is Nothing Then 
objExcel.Quit 
End If 
Set objWorksheetReque=Nothing
Set objWorksheetAccep=Nothing
Set objWorkbookReque=Nothing
Set objExcel=Nothing
End Function



Regards,
Venkat.Batchu

asked Apr 24, 2012 by anonymous  
    

2 Answers

0 votes
Appreciate it. This is very helpfull

Thanks,

Sri
answered Jun 8, 2012 by anonymous  
0 votes

create object for xl

option explicit

dim exo,wbo,wso,wbo1,wso1,i,a,b,c,d,e,f

set exo=createobjct("excel.application")

set wbo=exo.workbooks.open("path of xl file")

set wso=wbo.worksheets("sheet1")

set wbo1=exo.workbooks.add

set wso1=wbo.worksheets("sheet1")

now get the all row count of xl

i=1 y means first row xl column names

nor=wso.usedranged.rows.count

for i=1 to nor step 1

a=wso.cells(i,1)

b=wso.cells(i,2)

c=wso.cells(i,3)

d=wso1.cells(i,1)=a

e=wso1.cells(i,2)=b

f=wso1.cells(i,3)=c

next

wbo1.saveas("path of saved file")

set wso1=nothing

set wbo1=nothing

set wso=nothing

set wbo=nothing

set exo=nothing

answered Sep 24, 2012 by anonymous  
...