Hi..
This should do it..
I didn't quite understand what the "ISU" value was meant to be.. so I assumed it was a Name abbreviation (of the Test Executor)...
To test .. I have added a few rows of "AFA" as the executor in your test case workbook for each sheet.. so i autofiltered on Column 9 (not 10).. but this will be easy to change if my assumption is wrong..
Click the button and type "AFA" .. no quotation marks.. into the input box..
It will then loop through each sheet in your test case workbook.. autofilter for any rows that were tested by "AFA" and copy them to the relevant Sheet in your Master Workbook.
I have added both files in a Zip file below..
Private Sub CommandButton1_Click()
Dim lr As Long, lr2 As Long, n As Long
Dim CpyRng As Range, CpyToRng As Range
Dim wb As Workbook
Dim fname As String, wbname As String, wbstr As String
With Application
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
Set wb = ThisWorkbook
myPath = wb.Path & "\"
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = myPath 'this is the default folder shown
.AllowMultiSelect = False
.Filters.Add "Excel Files", "*.xl*", 1 'default
.Show
If .SelectedItems.Count > 0 Then
fname = .SelectedItems(1)
Else
Exit Sub
End If
End With
Workbooks.Open Filename:=fname
wbname = Split(fname, "\")(UBound(Split(fname, "\")))
ISU = InputBox("Enter ISU", "ISU", "")
With Workbooks(wbname)
For i = 3 To Worksheets.Count - 1
wbstr = Workbooks(wbname).Sheets(i).Name
lr = Workbooks(wbname).Sheets(wbstr).Range("A" & Rows.Count).End(xlUp).Row + 1
lr2 = ThisWorkbook.Sheets(wbstr).Range("A" & Rows.Count).End(xlUp).Row + 1
Workbooks(wbname).Sheets(wbstr).Range("A15:M" & lr - 2).AutoFilter 9, ISU
n = Sheets(Sheets(i).Name).Range("A15:M" & lr - 2).SpecialCells(12).SpecialCells(2).Count
If n > 13 Then
'Setup the Ranges to Copy From and To
Set CpyRng = Workbooks(wbname).Sheets(wbstr).Range("A15:M" & lr - 2).Offset(1).SpecialCells(12)
Set CpyToRng = ThisWorkbook.Sheets(wbstr).Range("A" & lr2)
CpyRng.Copy Destination:=CpyToRng
End If
Next i
End With
With Application
.EnableEvents = True
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
Bookmarks