Hi Chandoo,
I am new to Excel VBA, I want to copy data from excelsheet (Source Workbook (Local drive)) to another excelsheet with overwriting feature, that is where the below code is running. But unfortunately its open a new excel sheet every time i run it.
I have a tool which generates excel report every 5 min and with a VBA code its getting saved to my local drive. Now I want to copy data from the file which is saved locally to my excel file to cross verify both files.
Below is the working code.
Sub extractDataFromClosedFile()
OnErrorGoTo ErrHandler
Application.ScreenUpdating =False
Dim src As WorkbookSet src = Workbooks.Open("C:\Users\test.xls",True,True)
Dim iTotalRows AsInteger
iTotalRows = src.Worksheets("Sheet1").Range("A1:A"& Cells(Rows.Count,"A").End(xlUp).Row).Rows.Count
Dim iCnt AsInteger
For iCnt =1To iTotalRows
Worksheets("Sheet6").Range("A3"& iCnt).Formula = src.Worksheets("Sheet1").Range("b"& iCnt).Formula
Next iCnt
src.Close FalseSet src =Nothing
ErrHandler:
Application.EnableEvents =True
Application.ScreenUpdating =True
Debug.Print Err.Description
EndSub
Basically you want to copy data from WorkBook1 (Source Workbook (Local drive)) to another workbook, that is where the above code is running
I am new to Excel VBA, I want to copy data from excelsheet (Source Workbook (Local drive)) to another excelsheet with overwriting feature, that is where the below code is running. But unfortunately its open a new excel sheet every time i run it.
I have a tool which generates excel report every 5 min and with a VBA code its getting saved to my local drive. Now I want to copy data from the file which is saved locally to my excel file to cross verify both files.
Below is the working code.
Sub extractDataFromClosedFile()
OnErrorGoTo ErrHandler
Application.ScreenUpdating =False
Dim src As WorkbookSet src = Workbooks.Open("C:\Users\test.xls",True,True)
Dim iTotalRows AsInteger
iTotalRows = src.Worksheets("Sheet1").Range("A1:A"& Cells(Rows.Count,"A").End(xlUp).Row).Rows.Count
Dim iCnt AsInteger
For iCnt =1To iTotalRows
Worksheets("Sheet6").Range("A3"& iCnt).Formula = src.Worksheets("Sheet1").Range("b"& iCnt).Formula
Next iCnt
src.Close FalseSet src =Nothing
ErrHandler:
Application.EnableEvents =True
Application.ScreenUpdating =True
Debug.Print Err.Description
EndSub
Basically you want to copy data from WorkBook1 (Source Workbook (Local drive)) to another workbook, that is where the above code is running