Lesson#183: Insert zeroes in all empty cells in a selected range with VBA

Lesson#183: Insert zeroes in all empty cells in a selected range  with VBA

Here we are going to learn a VBA code to insert zeroes in all empty cells in a selected range.

  1. 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 your VBA macro code:

    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#185: How to make a digital clock 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 *

    *