With the help of AB33 (AB33 thanks for that
) you get the revisted code, in the attached file.
You find the code here:
Sub integratie_Oeldere_revisted_vs2()
Dim wsTest As Worksheet
'check if sheet "Consolidated" already exist
Const strSheetName As String = "Consolidated"
Set wsTest = Nothing
On Error Resume Next
Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
On Error GoTo 0
If wsTest Is Nothing Then
Worksheets.Add.Name = strSheetName
End If
With Sheets("Consolidated")
.UsedRange.ClearContents
.Range("A1:G1").Value = Array("sheet", "Year", "Month", "Project Leader", "Project Code", "Target alloted", "target covered")
For Each sh In Sheets
With sh
If .Name <> "Consolidated" And .Name <> "Summary" Then
Rng = .Cells.Find("*", , , , xlByRows, xlPrevious).Row - 1
NR = Sheets("Consolidated").Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
If Rng > 0 Then
Sheets("Consolidated").Cells(NR, 1).Resize(Rng) = .Name
Sheets("Consolidated").Cells(NR, 2).Resize(Rng, 6) = .Range("A2").Resize(Rng, 6).Value
End If
End If
End With
Next
.Columns("A:Z").EntireColumn.AutoFit
End With
End Sub
Bookmarks