VBA Code s not working even though the sum of filtered values are equal to 0.

mrahulkanth

New Member
Joined
Apr 25, 2019
Messages
27
VBA Code:
Set SumRange = ReconWS.Range(Cells(2, AmountFilter), Cells(ReconRows, AmountFilter)).SpecialCells(xlCellTypeVisible)
If Application.WorksheetFunction.Sum(SumRange) = 0 Then
    ReconWS.Range(Cells(2, MatchedItem),Cells(ReconRows,MatchedItem)).SpecialCells(xlCellTypeVisible).Select
    Selection.Value = "Matched to zero"

I have written this code to verify if sum of filtered values is equal to 0 or not. Even though the sum of filtered values is equal to 0, this code is not working.
I also checked the format of filtered values - I can see that in some places the sum is 0 ; 0.00 ; (0.00). But all three formats are equal to 0 right? but the code is not working. Please help!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I have 3 filtered cells based on criteria
1. 170.56
2. (85.28)
3. (85.28)

msgbox is showing the first visible cell which is 170.56
 
Upvote 0
Which explains it's not working, the msgbox value is the value to are comparing to zero.
Jason has given a very possible reason.
 
Upvote 0
ReconRows covers all the rows in the sheet and from that we are considering only filtered right?.
Filters are working perfectly but the only problem here is that sum is coming to 0, but the code is treating it as not matched to zero. I see a small difference is when I observe the sums of filtered cells in status bar... it displays in different ways like 0.00 & (0.00)
 
Upvote 0
Wrong, it is not summing the cells. What is the value of ReconRows, when you set the sumrange?
ReconRows is something like Lastrow. So from 2nd row till last row I’m considering and from that also, we are taking special visible cells. Please correct me if I’m wrong.
 
Upvote 0
What is the actual value of it?
The reason I ask is that if the message box only gave you the value of the first filtered cell, that if the only cell in the sumrange.
 
Upvote 0
But what is the value of ReconRows? If it is not defined correctly then that could be the source of the problem.

Try adding the line
VBA Code:
MsgBox SumRange.Address
What does that tell you?

To eliminate any rounding errors, I would suggest changing your code to
VBA Code:
If Round(Application.WorksheetFunction.Sum(SumRange), 2) = 0 Then
but I don't think that will fix the entire problem.
 
Last edited:
Upvote 0
Cross posted VBA Code s not working even though the sum of filtered values are equal to 0. - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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