what is the code that is used by excel to divide one number by another, and how this would be expressed if we were to do a UDF version?

jco10222

New Member
Joined
Jan 12, 2015
Messages
1
Hi, I am trying to find out what is the code that is used when software such as excel divide one number by another, and how this would be expressed as a user defined function.For example if you wanted to find A, where A = B / C. Then would the code do a do loop of C = C + C, until C > B?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I am trying to find out what is the code that is used when software such as excel divide one number by another, and how this would be expressed as a user defined function. For example if you wanted to find A, where A = B / C. Then would the code do a do loop of C = C + C, until C > B?

I assume you mean: A = A + 1 until A*C > B.

In Excel, that is ROUNDUP(B1/C1,0) or CEILING(B1/C1,1).

In VBA, that is WorksheetFunction.RoundUp(B/C,0) or WorksheetFunction.Ceiling(B/C,1).

I don't see any reason to use a UDF since Excel functions exist. But if you insist, I would write:
Code:
Function myDiv(B As Double, C As Double) As Double
    myDiv = WorksheetFunction.RoundUp(B/C,0)
End Function

I use type Double just in case B, C or myDiv might be larger than 2,147,483,647, the max for type Long.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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