Lesson#182: Color all empty cells in red in a selected range with VBA
Here I shall show you a VBA code that colors all empty cells in red in a selected range.
- Open the VBA editor: In Excel, press Alt + F11 to open the VBA editor.
- Create a new module: In the VBA editor, go to the Insert menu and select Module. This will create a new module where you can write your VBA code.
Here is a VBA macro that you can use to insert zeroes in all empty cells in a selected range:
Sub InsertZeroesInEmptyCells()
' Loop through the selected cells
Dim cell As Range
For Each cell In Selection
' If the cell is empty, set the cell value to 0
If IsEmpty(cell) Then
cell.Value = 0
End If
Next cell
End Sub
To use this macro, select the range that you want to check for empty cells and run the macro. It will insert zeroes in all empty cells in the selected range.
Leave a Reply