Hi Kim,
To avoid the potential problem of column specification,
try the following version:
'================>>
Public Sub Tester()
Dim WB As Workbook
Dim sh As Worksheet
Dim destSH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim Rng2 As Range
Dim iRow As Long
Dim CalcMode As Long
Const sStr As String = "keep" '<<===== CHANGE
Set WB = Workbooks("MyBook.xls") '<<===== CHANGE
Set sh = WB.Sheets("Sheet1") '<<===== CHANGE
With sh
iRow = LastRow(sh)
Set rng = sh.Range("A1:A" & iRow)
End With
On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
For Each rCell In rng.Cells
If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") = 0 Then
If Rng2 Is Nothing Then
Set Rng2 = rCell
Else
Set Rng2 = Union(rCell, Rng2)
End If
End If
Next rCell
If Not Rng2 Is Nothing Then
With WB
Set destSH = .Worksheets.Add( _
After:=.Sheets(.Sheets.Count))
End With
With destSH
Rng2.EntireRow.Copy Destination:=destSH.Range("A1")
.Name = Format(Date, "mmmm")
.Copy
End With
With ActiveWorkbook
.SaveAs Filename:=destSH.Name & ".xls"
.Close SaveChanges:=False
End With
End If
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'--------------->
Function LastRow(sh As Worksheet, _
Optional rng As Range)
If rng Is Nothing Then
Set rng = sh.Cells
End If
On Error Resume Next
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'<<================
---
Regards,
Norman
|