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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Not working in what way?

Runtime error?
Does nothing?
Does something, but not what is expected?
Something else?

Cells is unqualified (no sheet name in front) in several places, so that could be a problem depending on which sheet is active.

Regarding formatting, anything greater than (0.005) and less than 0.005 will appear as 0 with a format of 0.00 but will still have a non zero value for the purpose of your sum function. Number formats only affect the appearance of the numbers, the original value still remains in the background.
 
Upvote 0
Hi @jasonb75 . Actually the code does nothing even though the sum of filtered values are equalling to 0. I don’t why it’s happening like that. For some filters it’s working fine when the sum is equal to 0. But in some filters it’s not working(does nothing) and skips to the next step. Please help!
 
Upvote 0
If you add this msgbox as shown
VBA Code:
MsgBox Application.WorksheetFunction.Sum(SumRange)
If Application.WorksheetFunction.Sum(SumRange) = 0 Then
what does it say when you expect it to be zero?
 
Upvote 0
Does it make any difference if you use
VBA Code:
Set SumRange = ReconWS.Range(ReconWS.Cells(2, AmountFilter), ReconWS.Cells(ReconRows, AmountFilter)).SpecialCells(xlCellTypeVisible)
MsgBox Application.WorksheetFunction.Sum(SumRange)
 
Upvote 0
No @Fluff . Actually it doesn’t prompt any error, but despite being the sum of filtered values equal to 0, it update the cells as “Not Matched”. That’s my problem. I just want that if the sum of filtered(visible) cells equals to 0, then it should update as “Matched to Zero”.
 
Upvote 0
What does the message box say?
 
Upvote 0
And what was that value?
What EXACTLY did the message box say?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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