S
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Columns("F").AutoFilter _
field:=1, _
Criteria1:=0
Rows.SpecialCells(xlCellTypeVisible).EntireRow.Delete
- Show quoted text -
The code was more complicated than I originally expected
Sub removerows()
Columns("F").AutoFilter _
field:=1, _
Criteria1:=0
Rows.SpecialCells(xlCellTypeVisible).EntireRow.Delete
FirstRow = 1
RowCount = FirstRow
ID = Range("A" & RowCount)
Do While Range("F" & RowCount) <> ""
NextID = Range("A" & (RowCount + 1))
If NextID <> "" Then
If ID <> NextID Then
'sum the rows from FirstRow to present Row
Set SumRange = Range(Range("F" & FirstRow), _
Range("F" & RowCount))
Total = WorksheetFunction.Sum(SumRange)
If Total = 0 Then
Rows(FirstRow & ":" & RowCount).Delete
RowCount = FirstRow
Else
RowCount = RowCount + 1
FirstRow = RowCount
End If
ID = Range("A" & RowCount)
End If
Else
RowCount = RowCount + 1
End If
Loop
End Sub
- Show quoted text -
The microsoft Autofilter wasn't working correctly. I got rid of it anddid
the deletes in my code.
Sub removerows()
FirstRow = 2
RowCount = FirstRow
ID = Range("A" & RowCount)
Do While Range("F" & RowCount) <> ""
Grandtotal = Range("F" & RowCount)
If Grandtotal = 0 Then
Rows(RowCount).Delete
Else
NextID = Range("A" & (RowCount + 1))
If NextID <> "" Then
If ID <> NextID Then
'sum the rows from FirstRow to present Row
Set SumRange = Range(Range("F" & FirstRow), _
Range("F" & RowCount))
Total = WorksheetFunction.Sum(SumRange)
If Total = 0 Then
Rows(FirstRow & ":" & RowCount).Delete
RowCount = FirstRow
Else
RowCount = RowCount + 1
FirstRow = RowCount
End If
ID = Range("A" & RowCount)
End If
Else
RowCount = RowCount + 1
End If
End If
Loop
End Sub
- Show quoted text -
Thx Joel. It works as was required.
One last bit if you can add.
After this macro ends & we have the desired table, is there a
possibility to remove a row for which there is value in cell in
columnE but corresponding columnD cell is blank. If you can add this
step in same macro but at the end of what it has done so far. Putting
it in start will vary the result.
Thx alot once again.
Waiting for reply.- Hide quoted text -
- Show quoted text -
Sub removerows()
FirstRow = 2
RowCount = FirstRow
ID = Range("A" & RowCount)
Do While Range("F" & RowCount) <> ""
Grandtotal = Range("F" & RowCount)
If Grandtotal = 0 Then
Rows(RowCount).Delete
Else
NextID = Range("A" & (RowCount + 1))
If NextID <> "" Then
If ID <> NextID Then
'sum the rows from FirstRow to present Row
Set SumRange = Range(Range("F" & FirstRow), _
Range("F" & RowCount))
Total = WorksheetFunction.Sum(SumRange)
If Total = 0 Then
Rows(FirstRow & ":" & RowCount).Delete
RowCount = FirstRow
Else
RowCount = RowCount + 1
FirstRow = RowCount
End If
ID = Range("A" & RowCount)
End If
Else
RowCount = RowCount + 1
End If
End If
Loop
RowCount = 2
Do While Range("F" & RowCount) <> ""
If Range("D" & RowCount) = "" And _
Range("E" & RowCount) <> "" Then
Rows(RowCount).Delete
Else
RowCount = RowCount + 1
End If
Loop
End Sub
- Show quoted text -
worked like a charm ; )Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.