mtagliaferri
Board Regular
- Joined
- Oct 27, 2004
- Messages
- 156
I have found through the forum the below code to copy data from a closed excel file to the workbook as soon as this is open, this works fine but it is copying only the column A.
I need to copy columns A to F or ideally specific columns A, B, E and F.
I am strugling to get the code right by selecting the correct columns to copy.
I need to copy columns A to F or ideally specific columns A, B, E and F.
I am strugling to get the code right by selecting the correct columns to copy.
VBA Code:
Option Explicit
Private Sub Workbook_Open()
Call ReadDataFromCloseFile
End Sub
Sub ReadDataFromCloseFile()
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Dim src As Workbook
Set src = Workbooks.Open("C:\Users\MT\Desktop\MasterFile.xlsx", True, True)
Dim iTotalRows As Integer
iTotalRows = src.Worksheets("sheet1").Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Rows.Count
Dim iCnt As Integer
For iCnt = 1 To iTotalRows
Worksheets("Sheet1").Range("A" & iCnt).Formula = src.Worksheets("Sheet1").Range("A" & iCnt).Formula
Next iCnt
src.Close False
Set src = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub