0
Thanks

A few words of thanks would be greatly appreciated.

Excel – One cell calculation



Issue


Need a programme that calculates sum every time I put in one cell a number. For example, in cell A1 to put the number: 1, 1200, 0.50 and in cell B1 to calculate the sum of ( 1,1200,0.50)
If anyone could help me,

Thank you in advance.

Solution


As long as there are 3 numbers and configuration same
first number comma space second number comma space third number
then the following macro will get you the result in B1


A formula can be built up but for me it will be complicated.

The macro is:

Sub test()
Dim j, j1, k, k1, m, m1, n
j = InStr(Range("a1").Value, ",")
j1 = Left(Range("A1").Value, j - 1)
k = InStr(j + 1, Range("A1").Value, ",")
k1 = Mid(Range("A1").Value, j + 2, k - 4)
m1 = Right(Range("A1").Value, Len(Range("A1").Value) - k)
n = WorksheetFunction.Sum(j1, k1, m1)
'MsgBox n
Range("B1") = n
End Sub

Note


Thanks to venkat1926 for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Excel – One cell calculation », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!