Is there a formula that adds, subtracts, multiplies, and or divides two digit numbers in a single cell?

MrsFrankieH

Active Member
Joined
Mar 25, 2011
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Are there formulas that will add, subtract, multiply, and/or divide data from two-digit numbers in a single cell?

I appreciate any help I can get. Thank you in advance.

 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
First, how are the numbers stored in F1:J1? In order to get a leading 0, you can either store the number as a number and use a custom format, or you can store the number as text. Depending on the answer, the formulas could be different.

Next, how are you computing subtraction? It appears that it's the bigger number minus the smaller number, with 0s being treated as a 10.

And division? Big number divided by small number? Any 0 gives a 0 answer?
 
Last edited:
Upvote 0
First, how are the numbers stored in F1:J1? ... either ... a number and use a custom format, or you can store the number as text.
I'm assuming "Number Stored as Text", based on the little triangles at the top left of those cells in the image. Based on that, my suggestions are:

Excel Workbook
EFGHIJ
10309203639
2
3Addition39292
4Subtraction71836
5Multiplication 87
6Division 23
2 digit operations
 
Upvote 0
Here is a UDF version. The first argument is the cell with the number in it, and the second argument is the operation you want to perform. e.g. =TWODIGIT(A1,"+")

Code:
Function TWODIGIT(num As String, op As String)
Dim SP As Variant: SP = Split(StrConv(num, vbUnicode), Chr(0))

TWODIGIT = Evaluate(SP(0) & op & SP(1))

End Function

There is still the question on division as to which number is the numerator and which is the denominator. This code assumes that the first number is the numerator.
 
Upvote 0
Not as streamlined as the last, but this UDF replicates the results in the OP.

Code:
Function TWOII(num As String, op As String) As Variant
On Error GoTo ERH:
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")
Dim res As Double
Dim ret As Variant

AL.Add Right(num, 1)
AL.Add Left(num, 1)

res = Evaluate(Join(Array(AL(0), AL(1)), op))

If (AL(1) = "0" Or AL(0) = "0") And op = "-" Then
    If AL(1) = "0" Then
        TWOII = 10 - AL(0)
    Else
        TWOII = 10 - AL(1)
    End If
    Exit Function
End If

If res > 9 Then
    ret = Right(res, 1)
Else
    ret = res
End If

If ret = 0 Then TWOII = vbNullString Else TWOII = CDbl(ret)

Exit Function

ERH:

If Err.Number = 13 Then
    TWOII = vbNullString
Else
    MsgBox Error$
End If

End Function
 
Upvote 0
Hello again Eric!! Thanks for your response!
The numbers aren't stored per se, I would either input them of copy and paste them from another source. The way I'm computer subtraction is large to small because I don't want a negative. Yes, "0"s are treated as 10 and for division, as long as the answer is whole, any formula will do. If there's a division where the number has a "." in it (i.e. 3.4 or something) that would show as 0.

Thank you so much for your help again! :)
 
Upvote 0
Thank you Peter and it's great to see you again! I'm at a loss when it comes to excel terminology but I'm learning still. :)
Thank you for the formulas, I'll keep you posted as to how it works out.
Thanks again!
 
Upvote 0
Thank you Irobbo314! I appreciate your help!
I'm just getting acquainted with codes so I will add your code to my repertoire to study and learn.
You're amazing! Thank you!!
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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