Sub GetRedCells()
Dim strMyBook As String, strFilterBy As String
Dim cell As Range, MyRange as Range
Dim TempBook As Workbook
On Error GoTo ErrorHandler
Application.ScreenUpdating = False
Set TempBook = Workbooks.Add
'Change line below to suit
strMyBook = "IMF stage starts wk " & CStr(VBAWeekNum(Now(), 1))
strMyBook = strMyBook & "." & CStr(Application.WorksheetFunction.Weekday(Now())) & ".xls"
strMyBook = Application.InputBox("Enter workbook name", "Get Red Cells", strMyBook, , , , , 2)
strMyBook = "\\networkserver\users\adamsb\" & strMyBook
Workbooks.Open Filename:=strMyBook
Range([A1], [IV1].End(xlToLeft)).Copy Destination:=TempBook.Sheets(1).Range("A1")
ActiveSheet .ShowAllData
' Change Criteria1 to suit
strFilterBy = Application.InputBox("Enter Filter Criteria", "Get Red Cells", "S03B", , , , , 2)
Range("D:D").AutoFilter Field:=1, Criteria1:=strFilterBy
if Application.WorksheetFunction.CountA(Range("D:D")) < 2 then
msgbox "There are no entries for " & strFilterBy
exit sub
end if
Set MyRange = Range([E2], range("E65536).End(xlup))
For Each cell In MyRange.SpecialCells(xlCellTypeVisible)
If cell.Interior.ColorIndex = 3 Then _
cell.EntireRow.Copy Destination:=TempBook.Sheets(1).Range("A65536").End(xlUp).Offset(1, 0)
Next cell
ActiveWorkbook.Close False
Application.ScreenUpdating = True
On Error GoTo 0
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Number & " (" & Err.Description & ")"
End Sub
Function VBAWeekNum(D As Date, FW As Integer) As Integer
VBAWeekNum = CInt(Format(D, "ww", FW))
End Function