I added a check for "For Year". As for the file loop, it opens only files that have the value of sExt in the file name.
Sub Not_Tested()
Dim sExt As String
Dim sSourcePath As String
Dim sOutputPath As String
Dim sSearchString As String
Dim sFileName As String
Dim wb As Workbook
Dim v As Variant
Dim x As Long
Dim y As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
sExt = ".xlsx" 'Change as needed
sSourcePath = "C:\MyDocuments" 'Change as needed
sOutputPath = "C:\MyDocuments\Output" 'Change as needed
sSearchString = "Approximate # of persons covered at end of policy or contract year"
sSourcePath = sSourcePath & "\"
sOutputPath = sOutputPath & "\"
sFileName = Dir(sSourcePath)
Do While Len(sFileName) <> 0
If InStr(sFileName, sExt) Then
Set wb = Workbooks.Open(sSourcePath & sFileName, 0)
v = wb.Worksheets(1).UsedRange
For x = LBound(v, 1) To UBound(v, 1)
For y = LBound(v, 2) To UBound(v, 2)
If InStr(1, v(x, y), "For Year") Then v(x, y + 1) = v(x, y + 1) + 1
If IsDate(v(x, y)) Then v(x, y) = DateAdd("yyyy", 1, v(x, y))
If InStr(1, v(x, y), sSearchString) Then v(x, y + 1) = ""
With wb.Worksheets(1).UsedRange
If InStr(1, .Cells(x, y).NumberFormat, "$") Then v(x, y) = ""
End With
Next y
Next x
wb.Worksheets(1).UsedRange = v
wb.Close True, sOutputPath & sFileName
End If
sFileName = Dir()
Loop
With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
Bookmarks