Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Delete Problem

Status
Not open for further replies.

amal1973

Technical User
Jul 31, 2001
131
US
Hello
I have an excel sheet, Column “C” has numbers in it also column “F” has numbers
I want to write a VBA code that will access the sheet and will delete every row that has the value of zero in C and the value of 20 in F in the same row
This is what I did!!!!

Dim Sub zero()
Dim i As Integer
Dim Rng As Range

For i = Cells(Rows.Count, "C").End(xlUp).Row To 1 Step –1

If Cells(i, "C").Value = "0" And Cells(i, "F").Value = "20" Then
Cells(i).EntireRow.delete

End If
'Debug.Print (i)
'Debug.Print Cells(i, "C")
'Debug.Print Cells(i, "F")
Next i

Please advice
Thank you
 
You are comparing values (numeric) to strings.
Code:
If Cells(i, "C").Value = "0" And Cells(i, "F").Value = "20"

should be

If Cells(i, "C").Value = 0 And Cells(i, "F").Value = 20
Hope this helps...
 
well i did take them off ,but the problem that it deletes mostly everything .?? I just need to delete the row that has both a zero and a 20..
thanks
 
Hi,

Change
Code:
Cells(i).EntireRow.delete
to
Code:
Rows(i).EntireRow.Delete

:) Skip,
metzgsk@voughtaircraft.com
 
I cant thank you Enough :) Rows(i).EntireRow.Delete did the job…


Thank you
Amal1973
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top