vba help - substract not working

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I am unable to substract column A value with Colum B Value properly.
why Both are Giving Either positive addition or Negative Addition.


Book3
ABCDE
1ABDiffExpected Diff
25317.59-5317.5910635.180
35317.59-5317.59-10635.180
Sheet1
Cell Formulas
RangeFormula
C2C2=A2-B2
C3C3=B3-A3



Thanks
mg
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you want to get the difference then add the values.
With that data
A2-B2 is the same as 5317.59 - -5317.59 which is 5317.59+5317.59
 
Upvote 0
Why is the title "vba help..."? Your examples are Excel formulas.

Fluff already explained the major issue: add, instead of subtract.

But I wonder if you also need to explicitly round in order to avoid infinitesimal differences of the form 9.09E-13.

(We are probably unable to duplicate the rounding problem because XL2BB does not provide the exact binary values in column A and column B, which I assume are calculations in the actual Excel file.)

And yes, VBA and Excel results might differ in that respect, in part because of "tricks" that Excel plays.

In Excel, write:

=ROUND(A2+B2, 2)

In VBA, write:

Range("C2") = WorksheetFunction.Round(Range("A2") + Range("B2"), 2)

FYI, I use WorksheetFunction.Round instead of VBA Round because the latter rounds differently ("banker's rounding"). It might not make any difference in this case. But I eschew the use of VBA Round on principle.
 
Upvote 0
Hi Joeu and Fluff,

yes it should be excel formula help, I missed it,

and Thanks for your help, its working now. Thanks :)


Thanks
mg
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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