Simple Audits with VBA SpecialCells
The VBA SpecialCells method combined with background colors can be a simple and effective method to perform high-level worksheet audits. The process works by using a macro to apply colors to individual cells flagged as per the SpecialCells criteria.
For example, in Excel 2003 when you go to Edit -> Go To... -> Special, the following dialog box appears:
Options are available that allow you to select cells with constants, formulas, blanks, etc.
The same can be done with VBA and the SpecialCells method. The advantage of using VBA is that you can apply background colors to make the cells quickly visible. Additionally, there are even more options available via VBA than what you see in the dialog box.
To explain, you're boss asks you to audit the accuracy of a simple financial statement. To do so, start by making sure that formulas appear where they logically should. A simple VBA procedure using the SpecialCells method as presented below can be used to color all of the cells with formulas in the desired range yellow (yellow is tied to the index value number "6" below - this may be different on your machine.)
Sub Flag_Formulas()
Dim Rng As Range
Set Rng = Range("F9:I32")
Rng.SpecialCells(xlCellTypeFormulas).Interior.ColorIndex = 6
End Sub
After running the macro, the financial statement looks like this:
A quick look at the statement reveals that something is wrong in cell H19. Instead of seeing a cell with a formula it looks like somebody hard-coded a number.
This same process can be applied to other types of cells. The macro below can be used to flag hard-codes numbers:
Sub Flag_Hard_Coded_Numbers()
Dim Rng As Range
Set Rng = Range("F9:I32")
Rng.SpecialCells(xlCellTypeConstants, 1).Interior.ColorIndex = 6
End Sub
This macro flags text entries:
Sub Flag_Text()
Dim Rng As Range
Set Rng = Range("F9:I32")
Rng.SpecialCells(xlCellTypeConstants, 2).Interior.ColorIndex = 6
End Sub
For colors, if you want to specify an RGB number rather than an index number you can use a statement like:
Rng.SpecialCells(xlCellTypeConstants, 2).Interior.Color = RGB(255, 255, 204)
Finally, if you look up "SpecialCells" in Excel's VBA help there are even more options available. You can flag cells with comments, validation, same formatting, and even more.