Simple Problem - Please Help

M

mpeplow

Can anyone tell me why this is not working?

This is suppose to check each row on the sheet and if C * E < 3000 the
delete that row. I've rewritten this sub many time but cannot get it t
work properly.

In advance. Many Thanks!!


Sub Filter_Two()
Dim valPrice As Currency
Dim valQTY As Variant


FinalRow = ActiveSheet.Range("A65536").End(xlUp).Row

For i = 2 To FinalRow
'If ActiveSheet.Range("A" & i).Text = "" Then Exit Sub

valQTY = ActiveSheet.Range("C" & i).Value
valPrice = ActiveSheet.Range("E" & i).Value


If valPrice * valQTY < 3000 Then
Rows(i).Activate
Rows(i).Select
Rows(i).Delete
FinalRow = FinalRow - 1
End If
Next i
End Su
 
D

Die_Another_Day

You need to decrement i if you delete the current row. For Example
Product of Row 2 = <3000
Product of Row 3 = <3000
Your code says delete row 2, now row 3 is row 2 contain product <3000
your code says goto row 3 etc...
So insert this line after Rows(i).Delete
i = i - 1

HTH

Die_Another_Day
 
G

Guest

When you are deleting rows you want to work from the bottom up. Otherwise
every delete moves things around on you.

For i = FinalRow to 2 Step -1
'Don't change FinalRow
 

Ask a Question

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.

Ask a Question

Top