delete rows which have a one in them
There are a few things wrong with your code.
1.) You named you procedure delete(). Delete is a method in VBA and to
avoid any errors or confusion your should name your subs something
meaningful, like DeleteRows()
2.) You have undeclared variables. This can be a problem when trying to
debug code. You should make it a good practice of declaring your variables.
Dim FinalRow As Long
Dim i As Long
3.) I would recommend writting Cells(i, 8) like Cells(i, "H"). This will
make your code easier to read. For example, what column number is
"T"..........are you still trying to figure it out..........lol. It's easier
to use this Cells(i, 8). By the way the answer is 20.
4.) Plus, you missed spelled Cells in "finalrow = celss(rows.count,
1).end(xlup).row". It should be FinalRow = Cells(Rows.Count,
"A").End(xlUp).Row
5.) I see you are trying to use a Sub named finalrow(). No need to use
that. Delete that bit of code and use this.
Sub DeleteRows()
Dim FinalRow As Long
Dim i As Long
FinalRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = FinalRow To 2 Step -1
If Cells(i, "H") = 1 Then
Rows(i).EntireRow.delete
End If
Next i
End Sub
Sorry to go on and on just trying to help. Hope this helps! If so, let me
know, click "YES" below.
--
Cheers,
Ryan
"kyle" wrote:
i've got this code built that will delete a row if there is a one in column h
but it's not working
sub delete()
finalrow = celss(rows.count, 1).end(xlup).row
for i = finalrow to 2 step -1
if cells(i, 8) = 1 then
cells(i, 1).entirerow.delete
endif
next i
end sub
it doesn't work, what do you think is wrong?
|