Lesson#182: Color all empty cells in red in a selected range with VBA

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.

  1. Open the VBA editor: In Excel, press Alt + F11 to open the VBA editor.
  2. 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.

See also  Lesson#125: How to use function with VBA

Hi! I am Puspendu. I am the founder and author of Excelabcd. I am little creative person, blogger and Excel-maniac guy. I hope you enjoy my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

*