New Excel user needs help with simple Macro...

R

Rahim Kassam

Hello,

I am relatively need to Microsoft Excel and I need help creating a simple
Macro.

I would like to create a Macro that will:

- take the value of the selected value
- add it to the value of the cell below it
- if the sum of these two cells is zero - replace values of both cells with
an x
- move to the next set of cells in the same column repeat the procedure
- continue the procedure for the entire column
- once that is done, for each cell with an x delete the entire row

the reason why I do not wish to delelte the rows on the fly is because it is
possible that after a deletion of a pair, the value of the cell above it and
the value of the cell below could also sum to zero but I would want to keep
these.

I have tried to accomplish this with the use of the Macro recorder and VBA
in Excel 2000 but have been thus far unsuccessful, any help would be much
appreciated.

Thanks in advance.

R.
 
B

Bob Phillips

Rahim,

I have done the deleting directly as I do not see it being necessary to mark
them and then go back. I have tested the situation you mention and it
doesn't occur as we are working in row pairs.

Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
If iLastRow Mod 2 = 0 Then iLastRow = iLastRow - 1
For i = iLastRow To 1 Step -2
If Cells(i, "A").Value + Cells(i + 1, "A").Value = 0 Then
Cells(i, "A").Resize(2, 1).EntireRow.Delete
End If
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Top