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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain code

Status
Not open for further replies.

dignityy

Technical User
Oct 10, 2006
25
US
Can someone give a row by row explantion of how this code functions:

Dim i As Integer

i = 1

While Cells(i, 4) <> ""
Cells(i, 4).Select
If Cells(i, 4) = 0 Then
Rows(i).Delete
Else
i = i + 1
End If
Range("F1").Select
Wend


Obviously the goal is delete rows that have a zero in the dollars column but how does the code know which column to look at for those zeros? I have other columns that may have no value also? This appreaed to work for my application but I am leary about it.

Thankyou
 
The use of cells(x,y) means look at the cell on row x in column y. Here you are looking at column 4, the D column.

Dirk

Everything useful perishes through use....Should I not rejoice at being useless?
 
That would make sense why it worked for me.

Thanks
 
Works Fine.
Here we go.
Code:
While Cells(i, 4) <> ""
Declars a while loop.
This loop will continue until it comes across an empty cell.
Checks the cell at ROW i COLUMN 4.
Code:
Cells(i, 4).Select
Selects the cell at ROW i COLUMN 4.
Code:
If Cells(i, 4) = 0 Then
Checks the contents of cell at ROW i COLUMN 4 to see if it is equal to 0.
Code:
Rows(i).Delete
if it is then delete ROW i.
Code:
Else
If the contents of cell at ROW i COLUMN 4 is NOT equal to 0.
Code:
i = i + 1
increase the value of i by 1.
Code:
End If
end of the if statement.
Code:
Range("F1").Select
Select the cell Coloum F ROW 1.
Code:
Wend
End of while loop.

Deletes all rows where the contents of the column 4 cell is 0. Continues until an empty cell is reached. When finished Cell F1 is selected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top