PDA

View Full Version : Copy and paste count by last row



KK1966
08-19-2008, 07:18 AM
Hi

I need help with copying and pasting, actually can excel to open another file copying? and paste at the my active WS? if possible can u help me the code as I needs found the historical data "sheet name are same and the COLUMN also same, but the Rows are an unknow? I think i needs to open about 110 to 120 workboos so, brothers please advise me if excel can automatically to count by rows to copy and paste count by last row, so

-copy the open file at the sheet1 range A1 to A?
paste in to active excel count by COL A last row

Billion thank

mdmackillop
08-19-2008, 11:38 AM
This will copy the contents of column A in all workbooks in a folder to column A in the target workbook (in a separate folder for simplicity)

Sub CopyFiles()
Dim WBSource As Worksheet
Dim WS As Worksheet
Dim Tgt As Range
Dim Source As Range
Dim fName As String
Application.EnableEvents = False
Application.ScreenUpdating = False
Set WS = ThisWorkbook.Sheets(1)
ChDir "C:\AAA" '<===== Change to suit
fName = Dir("*.xls")
Do
Set Tgt = WS.Cells(Rows.Count, 1).End(xlUp).Offset(1)
Set WBSource = Workbooks.Open(fName).Sheets(1)
Set Source = Range(WBSource.Cells(1, 1), WBSource.Cells(Rows.Count, 1).End(xlUp))
Source.Copy Tgt
fName = Dir
ActiveWorkbook.Close False
Loop Until fName = ""
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

KK1966
08-19-2008, 10:25 PM
Dear mdmackillop

Sorry about I had late to real since get a busy work whiles

Thanks very much your help, may i have the code just base the DIALOGOPEN to click the file since most file name are under the date to saved, but he Sheets are same in the Shaat1"

Please