+ Reply to Thread
Results 1 to 11 of 11

Delete Rows When Column Is False

Hybrid View

  1. #1
    Banned User!
    Join Date
    03-06-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    295

    Delete Rows When Column Is False

    Is there any easy way to delete the rows when the cell value in Column A is False?

    Thank you
    Attached Files Attached Files

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Delete Rows When Column Is False

    there is no formula to do this. But you could use Filter from the Data menu that would hide those rows.

    If you want to delete them, you'll need a macro. Or you can easily do it manually after sorting your table.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Banned User!
    Join Date
    03-06-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    295

    Re: Delete Rows When Column Is False

    It sometimes is the easy solution that evades us. All I had to do was sort alphabetically on the True/False column and then delete the False rows. Thanks for the tips.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete Rows When Column Is False

    As Pierre says a macro would be needed.

    An obvious question though is how did the data arrive in this layout where every other row is redundant? If it comes as an import from some other system the sensible way would be to get the output from that system to suppress the rows that aren't needed
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    08-02-2013
    Location
    tacoma, wa
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Delete Rows When Column Is False

    This is a macro I use that works well. for your application you would need to change the FALSE values to blank with a " "

    You can use an if statement such as =IF(A1="FALSE"," ",A1) to convert all the FALSE cells to blanks.

    Then use this macro.

    
    Sub ClearCell()
        
    Application.ScreenUpdating = False
        
        
        Dim rng As Range
        Set rng = ActiveSheet.Range("A1")
    
        Dim i As Long
        
        For i = 1 To 15000
            
          'clears formula from any cell in range A1:A15000 that returns no value
                If rng.Cells(i, 1) = "" Then
                rng.Cells(i, 1).ClearContents
            
            End If
        
        Next i
    
    
    'deletes rows that are blank
        Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        Application.ScreenUpdating = True
    
    
    End Sub

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete Rows When Column Is False

    ...or rather than loop through all cells, which with large ranges can be slow. Just Autofilter the data for the False values, and use the instruction

    Range("your_range").SpecialCells(xlCellTypeVisible).EntireRow.Delete.

    This is the fastest way of I know of dealing with these sorts of block operations.

  7. #7
    Banned User!
    Join Date
    03-06-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    295

    Re: Delete Rows When Column Is False

    Thank you very much for the help

  8. #8
    Registered User
    Join Date
    08-02-2013
    Location
    tacoma, wa
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Delete Rows When Column Is False

    I see your point in replacing A:A with "your_range" but what does the xlCellTypeVisible do that xlCelltypeblanks does not? I'm very new to this so trying to learn also. Thanks!

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete Rows When Column Is False

    ...or better still

    Sub DeleteFalse()
        With Range("A1").CurrentRegion.Offset(1, 0)
            .AutoFilter field:=1, Criteria1:=False
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
    End Sub
    @Irack.

    The point is not whether blanks are better or worse than CellTypeVisible. They both have their place but in different circumstances.

    The point is that looping through each cell and testing carries a time overhead since with every iteration of the loop, VBA needs to jump back to the Excel App, test a cell and jump back to VBA to perform an action. With large ranges this can take a long time.

    With these sorts of things where you need to delete or perhaps copy a specific subset of a data population, the smart thing to do is to first filter the data, then address the whole rage that has been filtered and perform the single action of a block delete specifying the visible cells. i.e. two VBA operations rather than maybe hundreds.

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete Rows When Column Is False

    ..can't seem to edit at the moment.

    For the avoidance of doubt your CellTypeBlanks would work equally well in my macro but to get your blanks you've had to process a loop with all the time that takes

  11. #11
    Registered User
    Join Date
    08-02-2013
    Location
    tacoma, wa
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Delete Rows When Column Is False

    Good info to have. thank you for the assistance in understanding. this is like learning Chinese and knowing how to ask for the same thing 215 different ways......

+ 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. Replies: 2
    Last Post: 02-29-2016, 03:05 PM
  2. [SOLVED] Delete False data from a column
    By sky123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2015, 09:07 PM
  3. Delete entire column if word "False" exists
    By mikey3580 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 02:33 PM
  4. Replies: 5
    Last Post: 11-12-2012, 08:38 PM
  5. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  6. Sort Column, Delete Rows, Delete Column, Move Molumn, more inside?
    By motown in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-13-2008, 09:44 AM
  7. If formula result is false, how do I auto-delete that rows?
    By jbrenner51 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-16-2005, 01:52 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