I got something that doesn't work with this script.
It Open a directory with several xlsx files, copy them in one file and close 'em.
The line underliend SHOULD select the last column just copied and move to the first column of the file they've copied in, but it returns No Object error.
Any help?
Private Sub Macro()
Const Path As String = "PATH"
Dim FileName As String
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim WS3 As Worksheet
Dim LastRow As Long
Dim LastRow2 As Long
Set WS2 = ThisWorkbook.Worksheets(1)
FileName = Dir(Path & "\*.xlsx", vbNormal)
Application.ScreenUpdating = False
Do Until FileName = ""
If FileName <> ThisWorkbook.Name Then
Set WS = Workbooks.Open(Path & "\" & FileName).Sheets("Foglio1")
LastRow = WS.Cells(500, 1).End(xlUp).Row
WS.Range("A1").Resize(LastRow, 7).Copy WS2.Cells(LastRow2 + 1, 1)
LastRow2 = WS2.Cells(WS2.Rows.Count, 1).End(xlUp).Row
WS2.Cells(1, WS2.Columns.Count).End(xlToLeft).Column.Copy WS2.Cells(LastRow2 + 1, 1)
WS.Parent.Close 0
End If
FileName = Dir()
Loop
Application.ScreenUpdating = True
End Sub
Thanks
Bookmarks