highlight blank cells

  • How di I highlight blank cells in a range


    This has been asked before wherein all blank cells in a range color changed to green and solution was given as below

    Code
    Dim rng as Range
    On error resume next
    set rng = range(range("B7"),   range("G" & Range("A"&Rows.count).end(xlup).row)).specialcells(xlcelltypeblanks)
    on error goto 0
    if not rng is nothing then
         
        rng.Interior.ColorIndex = 4
    end if


    what i want is that the moment I type in the green cell the color should go bacl to normal.


    sample sheet attached

  • Re: highlight blank cells


    Try using the below with the included event handler as a macro attached to your workbook.



    Regards

  • Re: highlight blank cells


    sorry should be...


  • Re: highlight blank cells


    The code worke perfectly well, with only one problem.


    As you know when we type any text and press enter the cursor moves one step ahead.


    In this also after I press enter the cursor moves one step ahead with green box still highlighted. Now when I again take the cursor back to that box the green box becomes white.


    Is there anyway by which as soon as I press enter the green box becomes white.

  • Re: highlight blank cells


    Try this


    Code
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("B7").CurrentRegion) Is Nothing Then Exit Sub
        If IsEmpty(Target) Then
            Target.Interior.ColorIndex = 4
        Else: Target.Interior.ColorIndex = xlNone
        End If
    End Sub


    This is WorkSheet event code

Participate now!

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