Wednesday, April 1, 2015

Combining Excel files and making it one

'Open a file

file_Name = Application.GetOpenFilename() '-- to show the pop up window to find the file and open it
set owb=Application.Workbooks.Open(file_Name) '--capture the opened file in an object 'owb'
'MsgBox (file_Name) ' file_Name has full file path


' Count the number of Rows and Columns

Workbooks("file_Name").Sheets(1).Activate
lastrowR = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

lastcolumnR = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column



' Copy and Paste


Set shtToCopy = Workbooks("file_Name").Sheets(1).Range("R1:Y" & lastcolumnR)
shtToCopy.CopyWorkbooks("FCCT Project List_10-24.xlsx").Sheets(1).Range("R" & i & ":Y" & i)

No comments:

Post a Comment