Thea,
I think we got it this time.
this is the function
Private Function CopyDiagnostic(nameSheet As String)
Dim lro As Long
Dim lrowTarget As Long
Dim col As Long
Dim n As Long
lrow = Sheets("ALL").Cells(Rows.Count, 1).End(xlUp).Row
col = Sheets("All").Cells(1, Columns.Count).End(xlToLeft).Column
With Sheets("ALL")
'apply first filter filter for the data
.Range("$A$1:$P$" & lrow).AutoFilter Field:=7, Criteria1:=UCase(nameSheet)
Range("A1").CurrentRegion.Copy _
Destination:=Sheets(nameSheet).Range("A1")
Sheets(nameSheet).Cells.EntireColumn.AutoFit
'remove the previous filter
.Range("$A$1:$P$" & lrow).AutoFilter Field:=7
'now all the other filters
For n = 8 To col
' define the last row target
lrowTarget = Sheets(nameSheet).Cells(Rows.Count, 1).End(xlUp).Row + 1
'apply filter for the data
.Range("$A$1:$P$" & lrow).AutoFilter Field:=n, Criteria1:=UCase(nameSheet)
Range("A1").CurrentRegion.Offset(1, 0).Copy _
Destination:=Sheets(nameSheet).Cells(lrowTarget, 1)
Sheets(nameSheet).Cells.EntireColumn.AutoFit
'remove the previous filter
.Range("$A$1:$P$" & lrow).AutoFilter Field:=n
Next n
End With
End Function
and the main code
Sub CopyDiagnosticMain()
Dim sh As Worksheet
Application.ScreenUpdating = False
'first lets make sure we have an autofilter applied in the mail sheet
If Sheets("ALL").AutoFilterMode = False Then
Sheets("ALL").Range("A1").AutoFilter
End If
'go throu each one of the sheets
For Each sh In ThisWorkbook.Sheets
If Not sh.Name = "ALL" Then
Call CopyDiagnostic(sh.Name)
End If
Next
'remove the autofilter
Sheets("ALL").Range("A1").AutoFilter
Application.ScreenUpdating = True
End Sub
Thanks
Bookmarks