Auto Format Excel Cells with Error Value
With the simple Excel macro below, we can make all cells in active Worksheet that contains Error value in it, like #NULL, #Div/0!, #VALUE!, #Ref, #NAME?, #NUM!, And #N/A, will automatically having cell format that different/stand out among all other cells.
In this example, background color of the cell that contains the error value will automatically change color to red, each time the Excel Worksheet activated.
Private Sub Workbook_SheetActivate(ByVal Sh As Object) Dim errCells As Range Set errCells = Cells.SpecialCells(xlCellTypeFormulas, xlErrors) errCells.Interior.Color = 255 Set errCells = Nothing End Sub
Note that using the Cells.SpeciallCells function, we do not need to perform any looping to get Cells which contains the Error value.
This is just like automating Excel cell conditional formating process. Instead of selecting manually all the cells contains Error value or select all cells and then performing cell conditional format, with above code, we do it automatically using simple Excel VBA macro.
Related Entries
External Resources
- Microsoft Excel 2003/2007 Video Tutorials
Step-by-step video guide to mastering Charts, PivotTable, Data Analysis and Macro programming in Microsoft Excel in 5 hours.
- 101 Secrets of Microsoft Excel
Discover 101 of Excels little-known secrets that have been hiding right under your nose.
Tagged with: excel auto format cells, excel cell colorindex, excel cell conditional formating, excel cell format vba, excel error value, excel special cells