+ Reply to Thread
Results 1 to 7 of 7

How to look for empty cells in a range using vb?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    How to look for empty cells in a range using vb?

    Hi, here is my code, the problematic line is this: "if cell.value = "".. if TRUE I want Excel to color the entire row, isn't the way to look for empty cell?
    Sub look_for_empty()
    Worksheets("...").Activate
    With ActiveSheet
    Dim rng As Range
    Dim cell As Range
    Set rng = .UsedRange
    For Each cell In rng
    If cell.Value = "" Then
    cell.EntireRow.Font.ColorIndex = 4
    End If
    Next cell
    End With
    End Sub
    Please * if you like the answer

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to look for empty cells in a range using vb?

    ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).EntireRow.Font.ColorIndex = 4
    Assuming the blanks are not as a result of a formula.

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to look for empty cells in a range using vb?

    So you're trying to set font to green for all rows which contain a blank cell within the used range, right?

    Sub foo()
    Dim c As Range
    For Each c In ActiveSheet.UsedRange
        If c.Value = "" Then
            c.EntireRow.Font.ColorIndex = 4
        End If
    Next c
    End Sub
    This works for me...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to look for empty cells in a range using vb?

    Is the code not working? I tested it and it worked.

  5. #5
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to look for empty cells in a range using vb?

    @yudlugar thanks. Where in my code should I add your line?

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to look for empty cells in a range using vb?

    Replace it all:

    Sub look_for_empty()
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).EntireRow.Font.ColorIndex = 4
    End Sub
    Although if your code didn't work that probably won't either, are you sure they are blank and not a space or something? An example workbook might be helpful in this case.

  7. #7
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to look for empty cells in a range using vb?

    Thanks guys it works now..and I learnt somthing new.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Transfer cells range to another sheet if first cell of destination range is empty
    By kopapa in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-04-2013, 04:32 PM
  2. If the range A1:F1 and the cell H1 are not empty, then all range cells must be not em
    By loroverde in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-29-2013, 04:13 AM
  3. MACRO to empty a range of cells based on whether specified cell is empty
    By TBJV in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 10:35 PM
  4. shift range of cells to left if find the range of empty do while
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2012, 09:25 AM
  5. sum next two non-empty cells in a range
    By Spencer Hutton in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-09-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1