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.
- 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.
Leave a Reply