VBA Excel: change null value in any cell in a Range to zero

  • Hi, in Excel I want to use a marco to automate a process so that for all the cells in a Range, if any cell is null, it changes to value 0. How can I achieve that? Thanks!

  • Re: VBA Excel: change null value in any cell in a Range to zero


    Hey derricklo1980,


    The macro below replaces all blank cells in the range you currently have selected with zeros. Just highlight the section you want this performed on and then run the macro.


    Code
    Sub replace_blanks()
    Dim cellvar As Range
    For Each cellvar In Selection.Cells
    If cellvar.Value = vbNullString Then
    cellvar.Value = 0
    End If
    Next cellvar
    End Sub


    Cheers,
    -Wilson

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!