Hi Arkadi,
Now i am trying copy columns from 9 to till end but it is not happening properly. Code is as follows. Can you please help me out
Sub copydata()
Dim folderpath As String, filepath As String, filename As String
Dim lastrow As Long, lastcoloumn As Long, erow As Long
Dim wb As Workbook
Dim ws As Worksheet
folderpath = "D:\CFCM\"
filepath = folderpath & "*.*"
filename = Dir(filepath)
Do While filename <> ""
Set wb = Workbooks.Open(folderpath & filename)
Set ws = wb.ActiveSheet
lastrow = ws.Cells(Rows.Count, 9).End(xlUp).Row
lastcolumn = ws.Cells(2, Columns.Count).End(xlToLeft).Column
erow = ThisWorkbook.Worksheets("CFCM data").Cells(Rows.Count, 1).End(xlUp).Offset(9, 0).Row
ws.Range(Cells(2, 9), Cells(lastrow, lastcolumn)).Copy Destination:=ThisWorkbook.Worksheets("CFCM data").Cells(erow, 1)
Application.DisplayAlerts = False
wb.Close
filename = Dir
Range("A2") = "Entity Account Number"
Columns("A:G").Sort key1:=Range("A2"), _
order1:=xlAscending, Header:=xlYes
Loop
Application.DisplayAlerts = True
End Sub
Bookmarks