Consulting

Results 1 to 6 of 6

Thread: Need help with program deleting rows

  1. #1
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location

    Need help with program deleting rows

    code.jpgexcel.jpg

    Hey guys,
    I wanna remove every row where the sum of those 3 numbers equals Zero
    i dont know any further how it may work, guess i Need to kinda check for decimals aswell.
    Thanks in advance!

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Always delete Rows from the bottom up and Columns from right to left.

    Sub VBAX_SamT()
    Dim Rw As Long
    
    'From the bottom row on the sheet, Column B, Press Ctrl+UpArrow. Get the Row number. Count backwards by 1
    For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1
    
       'Use only one of the below IFs
       If Sum(Range("B" & Rw & ":D" & Rw) = 0 Then
       If Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then
       If Sum(Cells(Rw, "B").Resize(1, 3)) = 0 Then
    
          Rows(Rw).Delete
       End If
    Next Rw
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location
    Quote Originally Posted by SamT View Post
    Always delete Rows from the bottom up and Columns from right to left.

    Sub VBAX_SamT()
    Dim Rw As Long

    'From the bottom row on the sheet, Column B, Press Ctrl+UpArrow. Get the Row number. Count backwards by 1
    For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1

    'Use only one of the below IFs
    If Sum(Range("B" & Rw & "" & Rw) = 0 Then
    If Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then
    If Sum(Cells(Rw, "B").Resize(1, 3)) = 0 Then

    Rows(Rw).Delete
    End If
    Next Rw
    End Sub
    Hey,
    thanks for the help, but i m getting a syntaxerror for this line: For Rw = (Cells(Rows.Count. "B").End(xlUp).Row to 3 Step -1
    and i kinda can't figure out whats wrong.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    remove the dot after Count
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    And use only one of the three Ifs
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location
    Quote Originally Posted by p45cal View Post
    remove the dot after Count

    Quote Originally Posted by SamT View Post
    And use only one of the three Ifs

    Thanks for the super fast replies!


    I changed a few minor things so it works for me now, it looks like this:


    Sub VBAX_SamT()
    Dim Rw As Long

    For Rw = (Cells(Rows.Count, "B").End(xlUp).Row) To 3 Step -1


    If Application.WorksheetFunction.Sum(Range(Cells(Rw, 2), Cells(Rw, 4))) = 0 Then


    Rows(Rw).Delete
    End If
    Next Rw
    End Sub

Posting Permissions

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