I'd be tempted to rewrite this as
Sub FormatColumns()
Dim sht As Worksheet
Dim RollWorkbook As Workbook
Dim EncumbranceCell As Range
Dim MerchandiseCell As Range
On Error Resume Next
For Each sht In RollWorkbook.Worksheets
Set EncumbranceCell = sht.Cells.Find( _
What:="*ENCUMBRANCE*", _
After:=Cells(Rows.Count, Columns.Count), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False _
)
If Not EncumbranceCell Is Nothing Then
Intersect(sht.UsedRange, EncumbranceCell.EntireColumn).NumberFormat = "$#,##0.00"
Else
Err.Clear
End If
Set EncumbranceCell = Nothing
Next sht
For Each sht In RollWorkbook.Worksheets
Set MerchandiseCell = sht.Cells.Find( _
What:="*MERCHANDISE*", _
After:=Cells(Rows.Count, Columns.Count), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False _
)
If Not MerchandiseCell Is Nothing Then
Intersect(sht.UsedRange, MerchandiseCell.EntireColumn).NumberFormat = "$#,##0.00"
Else
Err.Clear
End If
Set MerchandiseCell = Nothing
Next sht
On Error GoTo 0
RollWorkbook.Activate
End Sub
I'm fastidious about error trapping. Also, this restricts number formatting to the used range in each worksheet. Maybe you want to extend this for many more rows, but I suspect you don't mean to extend it all the way down to row 1,048,576.
Beyond that, if ENCUMBRANCE or MERCHANDISE are found in the (k-1)th worksheet but not the kth worksheet, the EncumbranceC.. and MerchandiseC.. variables would retain the values from the (k-1)th worksheet rather than be set to 0 or Nothing. You have to reset those variables just before Next in each For loop.
Maybe not a potential problem, but avoid one anyway: if sht is type Worksheet, iterate over RollWorkbook.Worksheets rather than RollWorkbook.Sheets.
Finally, use sht.Cells rather than just Cells. You're not activating different worksheets as you iterate through RollWorkbook.Worksheets, so unadorned
Cells refers to ActiveSheet.Cells in each iteration.
Bookmarks