Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi
I need any function or macro to do this conditional task as below!
In excel file,I have a data from A1 to C300
then
criteria 1: Check if A1= A2 then
Criteria 2: Check if C1 = -C2 then
Criteria 3: delete rows A1 and A2.the above check and delele operation should be done up to A300 rows.
Any help?

Use this macro:
Sub RowDelete()
Dim currRow As Integer
currRow = 1
Do Until Cells(currRow, 1) = ""
If Cells(currRow, 1) = Cells(currRow + 1, 1) And _
Cells(currRow, 3) = -Cells(currRow + 1, 3) Then
Range(Cells(currRow, 1), Cells(currRow + 1, 1)).EntireRow.Delete
Else
currRow = currRow + 1
End If
Loop
End SubNote the following, though:
-the test for negative value is not 100%. Negative values often differ from positive at the Nth decimal place because of different rounding rules. So my usual method is to take the ABSOLUTE value of the SUM of the two, and compare it to a tolerance, say 0.01.
-rather than using a number like 300, I have just said "carry on until there is nothing in the A column". This might not be appropriate for your spreadsheet, and you should amend the "Do" statement to say something like Do Until CurrRow = 300.
However, for rough'n'ready, the above works.
Cheers
Tom

hi
Tks for your Macro.Its really working nice
Now i need an additional thing.In col. C, say i have 5 values corresponding to each same value in A.(ie., A1 to A5 have same A001 to which it will have different values in Col. C).
Now , in this 5 Col. C values, i may have 2 negative values and three positive values.
If we add those 2 negative values, it will match with any one of the positive value within those 5 Col. C values of A001.Like this ineed to check for all Col.A values.
Any clarifications pls.let me knowsuriya

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |