Results 1 to 4 of 4

find <> empty cell in range, delete entire row

Threaded View

  1. #1
    Registered User
    Join Date
    03-26-2011
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    2

    find <> empty cell in range, delete entire row

    This is my first post here, so welcome Everyone I'm just starting the adventure with programming and hope to learn more thanks to your experience (and count on your sense of humor and comprehension in case of lame questions ).

    My today's problem is as follows: I'm trying to write a macro that searches for not empty cell in given column and deletes entire row once the condition is fulfilled.
    So as to limit the range (not to search in entire column) I'm trying to specify last row in the table. However, the macro (see code below) is not working correctly - no error occurs but it still is not working as expected (deletes some rows, empty or not).

    If you could look into this and help me to understand where's en error in my way of thinking if would be great.


    Dim LastRow As Integer
    Dim LastCol As Integer
    Dim Cell As Range
    
    ' define last cells in row and column
    
    LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    LastCol = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
    
    ' search for not empty cells in column D (D2:LastRow); if cell not empty, delete entire row
    
    For Each Cell In Range(Cells(2, 4), Cells(LastRow, 4))
    If Cell.Value <> "" Then
    ActiveCell.EntireRow.Select
    Selection.Delete
    
    End If
    Next Cell
    Many thanks in advance!
    Last edited by Shell_; 03-26-2011 at 12:38 PM.

Thread Information

Users Browsing this Thread

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

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