+ Reply to Thread
Results 1 to 3 of 3

Delete row if total is equal to 0.00%

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Philadelphia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Delete row if total is equal to 0.00%

    Hello,

    I am attempting to build a macro that looks at a certain cell. If that cell is equal to 0.00%, then it will delete the entire row. I would need it to repeat the same function until it finds no more data in the selected cell. In addition, I have multiple tabs within the excel spreadsheet that are set up the same exact way. Is there a way for the macro to repeat the same task on any tab within the file?

    I am attaching a spreadsheet as a reference.

    Basic Summary:

    Column BI is where the macro would need to look for specific percentages. If the percentage equals 0.00%, then delete. If it is any higher than that, then keep the row and continue down the list. Repeat same function on tab 2 or any additional tabs.

    I am asking this question from a beginner standpoint, so I appreciate any type of advice.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Delete row if total is equal to 0.00%

    This will delete the rows base on your requirements for the active sheet. If you want to apply the same macro for all the worksheet, just loop the each sheet.

    Sub DeleteRow()
    Dim ws As Worksheet: Set ws = ThisWorkbook.ActiveSheet
    Dim LR As Long, i As Long
    
    With ws
    LR = .Cells(Rows.Count, 1).End(xlUp).Row
        For i = LR To 5 Step -1
            If .Cells(i, "BI").Value = 0 Then .Rows(i).Delete
        Next i
    End With
    End Sub

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Delete row if total is equal to 0.00%

    This should do it

    Option Explicit
    Sub abc()
    Dim RangeToDelete As Range
    Dim lastrow As Long, Ptr As Long
    Dim ws As Worksheet
    
     For Each ws In Worksheets
        With ws
            lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
            For Ptr = 4 To lastrow
                If .Cells(Ptr, "BI") = 0 Then
                    If RangeToDelete Is Nothing Then
                        Set RangeToDelete = .Cells(Ptr, "BI")
                    Else
                        Set RangeToDelete = Union(RangeToDelete, .Cells(Ptr, "BI"))
                    End If
                End If
            Next Ptr
            
            If Not RangeToDelete Is Nothing Then
                RangeToDelete.EntireRow.Delete
            End If
            Set RangeToDelete = Nothing
        End With
     Next
     
     Set RangeToDelete = Nothing
     Set ws = Nothing
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

+ Reply to Thread

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