+ Reply to Thread
Results 1 to 4 of 4

Macro that looks for different values in cells - having trouble with zero and blank

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263

    Macro that looks for different values in cells - having trouble with zero and blank

    I have a macro that looks up or down from the currently selected cell and looks for when the cell contents change, e.g. suppose you have a hundred entries of "dog" in a column and this changes at some point to "cat", the macro selects the cell at the change-over point by iterating through the cells and looking for when the cell value changes.

    However it doesn't know the difference between a blank cell and a cell with a zero in it (both equal zero according to VBA). I have a kind-of solution using WorksheetFunction approach (using Count or CountA) but it takes aaaages to run, presumably since it's using a worksheet function.

    Can anyone think of a more efficient way to check the contents of two cells? I need a quick way to compare the contents and flag up if one is blank and one contains a zero.

    Cheers!
    Rob
    Last edited by TheRobsterUK; 09-17-2014 at 07:36 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro that looks for different values in cells - having trouble with zero and blank

    Blank and zeros (With a figure 0) are not same. A cell with 0 has a value while a blank does not have.

  3. #3
    Forum Contributor
    Join Date
    01-30-2014
    Location
    England
    MS-Off Ver
    MS Office 2010, 2007, 2003
    Posts
    149

    Re: Macro that looks for different values in cells - having trouble with zero and blank

    If IsEmpty(ActiveCell.Value) Then
    Do one thing
    'else is optional
    Else
    Do something else
    End If
    Would that work for your blank cells?
    Last edited by Aaron092; 09-17-2014 at 07:32 AM. Reason: Change 'Blank' to 'Empty'

  4. #4
    Forum Contributor
    Join Date
    05-26-2004
    Location
    Halifax, UK
    MS-Off Ver
    Office 365 v2402
    Posts
    263

    Re: Macro that looks for different values in cells - having trouble with zero and blank

    Found that this works:

    If IsEmpty(current_cell) And Not IsEmpty(cell_down) Or IsEmpty(cell_down) And Not IsEmpty(current_cell) Then
           current_cell.Select
           MsgBox ("Solution found")
          Exit Sub
        End If

+ 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. Trouble creating macro for one blank row above with copy paste data
    By mikeclark206 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-26-2014, 12:01 AM
  2. Replies: 6
    Last Post: 04-11-2014, 04:45 AM
  3. [SOLVED] Macro to fill blank cells in column A based on non-blank cells
    By ktalamantez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2014, 02:47 PM
  4. How can I make a macro ignore blank cells? - Blank Cells have formulas
    By mz1161 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2013, 08:54 AM
  5. [SOLVED] Trouble with dinamic chart - Blank cells from if statement
    By Portuga in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 03-26-2013, 12:47 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