Computing.Net > Forums > Office Software > macro for conditional row deletion

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

macro for conditional row deletion

Reply to Message Icon

Name: suriya6in
Date: July 28, 2003 at 01:37:48 Pacific
OS: win9x
CPU/Ram: intel pII 64 mb
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: A Certain TH
Date: July 28, 2003 at 05:07:18 Pacific
Reply:

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 Sub

Note 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


0

Response Number 2
Name: suriya
Date: July 30, 2003 at 03:25:21 Pacific
Reply:

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 know

suriya


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: macro for conditional row deletion

Row delete macro www.computing.net/answers/office/row-delete-macro/1803.html

Row delete macro www.computing.net/answers/office/row-delete-macro/1577.html

Macro for Inserting Rows www.computing.net/answers/office/macro-for-inserting-rows/5313.html