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.
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!
[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
awesome!!! Thank you xld.
SHAZAM!