Macro to clear data where value sums to zero

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have values in Col b and percentages in Col G


Where the % is the same in Col G for eg 1% and the values in Col b for that % sums to zero , then the data in Col A:G to be cleared from row 3 onwards

In the sample data below A2:G3 to be cleared as the % is the same and the values in Col B for 1% sums to zero


It would be appreciated I someone can write code to do this for me


Your assistance in this regard is most appreciated



Book1
ABCDEFGH
1RefVatValuePercentage
2f915218.423308.921.00%
3f9150-18.42-3327.341.00%
4F9589-1052.11-3515.15.00%
5F9590-1793.81-3012.936.00%
6
7
8
9
10
11
12
13
Sheet1
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Am no VBA expert (so take a backup and check the results thoroughly,) but this works,

Assumes the following:
that by "clear" you mean clear the rows and not delete them
that you are on that sheet when you run the code
that the rows that need to be cleared are below each other as per your example
that only TWO rows need to be cleared each time, as per your example

Code:
Sub ClrPercent()
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 7) = Cells(i + 1, 7) And Cells(i, 2) + Cells(i + 1, 2) = 0 Then
Range(Cells(i, 1), Cells(i + 1, 7)).Clear
End If
Next i
End Sub
 
Last edited:
Upvote 0
I would like the 0 to be amended so that where the value I B sum to zero or up to a maximum of 0.00002 or -0.00002 then the rows that adds up to this value also to be cleared


your assistance is most appreciated
 
Upvote 0
Change the line to

Code:
If Cells(i, 7) = Cells(i + 1, 7) And Abs(Cells(i, 2) + Cells(i + 1, 2)) <= 0.00002 Then
 
Upvote 0
thanks for the help. I have tested the data further and where the % is the same in Col G and the values for a particular % in Col b adds up to zero are there is a small value after the decimal place for eg 0.00001, 0.000002 etc these must be cleared


See further example blow



Book1
ABCDEFG
1F5166-1532.915.00%
2F5166-2279.9615.00%
39255280-42.1715.00%
4NLK-92065442.1715.00%
5JLP705691532.915.00%
6916817PL2279.9615.00%
Sheet1
 
Upvote 0
That should be covered by the recent change since
0.000002 is less than 0.00002

If the value is not clearing then the %s in column G are not the same (maybe 14.9999% instead of 15%?)

Unfortunately I dont have any more time to spend on this as I am at work and am only able to take on small Excel problems in the spare time I have.
 
Upvote 0
I do appreciate your help, and fully understand your dilemma
 
Upvote 0

Forum statistics

Threads
1,215,090
Messages
6,123,061
Members
449,091
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top