Consulting

Results 1 to 3 of 3

Thread: Solved: If Subtotal equal to zero delete that paticular group.

  1. #1
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location

    Solved: If Subtotal equal to zero delete that paticular group.

    Hi Everyone,


    I have a workbook that uses Subtotals. My question is does anyone has a code that will look in column D and if the subtotal equal to zero then delete that subtotal group.

    Here is a sample of my workbook.
    SHAZAM!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim i As Long
    Dim LastRow As Long
    Dim rng As Range
    Dim StartRow As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    StartRow = 2
    For i = 2 To LastRow

    If .Cells(i, "A").Value = "Total" Then

    If .Cells(i, "D").Value = 0 Then

    If rng Is Nothing Then

    Set rng = .Rows(StartRow).Resize(i - StartRow + 1)
    Else

    Set rng = Union(rng, .Rows(StartRow).Resize(i - StartRow + 1))
    End If
    End If

    StartRow = i + 1
    End If
    Next i

    If Not rng Is Nothing Then rng.Delete
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    awesome!!! Thank you xld.
    SHAZAM!

Posting Permissions

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