View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Joe User[_2_] Joe User[_2_] is offline
external usenet poster
 
Posts: 905
Default Help with Excel VBA QUOTIENT

"JCIrish" wrote:
This seems like it should be easy, but i'm baffled!!
[....]
The only value I get is zero.


So am I, but not for the reason you might think.

What version of Excel/VBA are you using?


Ratio = Application.WorksheetFunction.Quotient(x, y)


WorksheetFunction.Quotient is not valid in my revision of Excel 2003 / VBA
6.3. So I get a VBA error, not zero.

The simple fix, indeed the better implementation unless you are trying to
test the VBA implementation of WorksheetFunction.Quotient, assuming that
works in your version of Excel/VBA:

Ratio = Int(x / y)


I want to put the quotient of Cells E20 and E38, both of which
contain positive integers, into Cell G40. The only value I get is zero.


What values have you tried in E20 and E38?

Zero is the correct answer when E20 < E38.

When E20 is 12 and E38 is 5, G40 is 2 with "Ratio=Int" fix above.


----- original message -----

"JCIrish" wrote in message
...
This seems like it should be easy, but i'm baffled!! In the code below,I
want
to put the quotient of Cells E20 and E38, both of which contain positive
integers, into Cell G40. The only value I get is zero. The code runs ok
but
obviously produces the wrong result. Can anyone tell me why this is? What
am
I missing? Thanks.

Sub ComputeAssetRatios()

Application.Worksheets("AssetAllocation").Activate

Dim Numerator As Range
Dim Denominator As Range
Dim Ratio
Dim x
Dim y
Dim z

Set Numerator = Worksheets("AssetAllocation").Range("E20")
x = Numerator.Value
Debug.Print

Set Denominator = Worksheets("AssetAllocation").Range("E38")
y = Denominator.Value
Debug.Print

Ratio = Application.WorksheetFunction.Quotient(x, y)
Range("G40").Select
Selection.Value = Ratio

Debug.Print

End Sub