How to sum columns only intregral numbers despite that have rows with text, decimals and percentual values?

Lacan

Board Regular
Joined
Oct 5, 2016
Messages
237
Office Version
  1. 365
Platform
  1. Windows
Hello Guys,
Hope you are OK!

Have 2 largest columns however in the example below that are only a sample
How to sum columns only intregral numbers despite that have rows with text, decimals and percentual values?
Thanks for all the help!!! 👍👍

Painel FARMÁCIAS_21.JUL.xlsx
ABCDEFGHI
1
2
3SALES ASALES B
4PYG MTH %Var MS (p.p.) PY MTH
5-3%-0,18
6OBJECTIVO1 100
71 000
8-0,55
910%500
101 869GOAL
11498
12TOTALTOTAL
13
14
15
Folha1
 
Is vba acceptable?
If "yes" then see if this user-defined function would do what you want.

VBA Code:
Function SumInt(rng As Range) As Long
  Dim c As Range
  Dim v As Variant
  
  For Each c In rng
    v = c.Value
    If IsNumeric(v) Then
      If Int(v) = v And InStr(1, c.Text, "%") = 0 Then
        SumInt = SumInt + v
      End If
    End If
  Next c
End Function

In my sample below col D is as post #9.
In col E, cell E7 appears as an integer but actually contains 100.32 so is excluded from the sum.
In col F, cell F7 is again 100.32 and cell F10 appears as an integer but is actually a text value of 100 so is also excluded from the sum.

Lacan.xlsm
DEF
3SALES ASALES ASALES A
4PYG MTH %PYG MTH %PYG MTH %
5-0.031431276-0.031431276-0.031431276
6OBJECTIVOOBJECTIVOOBJECTIVO
7100010001000
8-0.6789-0.6789-0.6789
90.10.10.1
10100010001000
110.390.390.39
127000%7000%7000%
13100010001000
14300020001000
Sheet1
Cell Formulas
RangeFormula
D14:F14D14=SUMINT(D5:D13)
 
Upvote 0
Solution

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Here is another option with formula:

You still didn't responde how you want to handle the values that are for example 1000.54. Truncate them? Round them? Ignore them altogether?

Anyway, here are all three options:
CELL if volatile, and it behaves a little weird, so you may need to force calculate (by pressing F9 or editing a cell with formula and hitting enter) if you change data before the calculation reflects the change.

Book6.xlsx
ABCDEFGHI
1
2TruncateRoundOnly Integers ignoring values that have decimals
3SALES A300030012000
4PYG MTH %
5-0.031431276
6OBJECTIVO
71000
8-67.9%
910%
101000
110.39
127000%
131000.65
14
Sheet8
Cell Formulas
RangeFormula
F3F3=LET(d, D3:D1000, format, BYROW(d, LAMBDA(x, CELL("format", x))), notPercentage, NOT(ISNUMBER(SEARCH("p", format))), v, IFERROR(VALUE(d), 0)*notPercentage, SUM(TRUNC(v, 0)) )
G3G3=LET(d, D3:D1000, format, BYROW(d, LAMBDA(x, CELL("format", x))), notPercentage, NOT(ISNUMBER(SEARCH("p", format))), v, IFERROR(VALUE(d), 0)*notPercentage, SUM(ROUND(v, 0)) )
H3H3=LET(d, D3:D1000, format, BYROW(d, LAMBDA(x, CELL("format", x))), notPercentage, NOT(ISNUMBER(SEARCH("p", format))), v, IFERROR(VALUE(d), 0)*notPercentage, isInt, v=INT(v), SUM(ROUND(v, 0)*isInt) )
 
Upvote 0
I think that you would need vba to do that since the cell that shows as 7000% actually just contains the integral number 70 and the % sign only appears due to the cell formatting, not due to the underlying number. Is vba acceptable?
Dear @Peter_SSs

Yes please, vba is acceptable.
Thank you very much! 🔝👍👍
 
Upvote 0
If "yes" then see if this user-defined function would do what you want.

VBA Code:
Function SumInt(rng As Range) As Long
  Dim c As Range
  Dim v As Variant
 
  For Each c In rng
    v = c.Value
    If IsNumeric(v) Then
      If Int(v) = v And InStr(1, c.Text, "%") = 0 Then
        SumInt = SumInt + v
      End If
    End If
  Next c
End Function

In my sample below col D is as post #9.
In col E, cell E7 appears as an integer but actually contains 100.32 so is excluded from the sum.
In col F, cell F7 is again 100.32 and cell F10 appears as an integer but is actually a text value of 100 so is also excluded from the sum.

Lacan.xlsm
DEF
3SALES ASALES ASALES A
4PYG MTH %PYG MTH %PYG MTH %
5-0.031431276-0.031431276-0.031431276
6OBJECTIVOOBJECTIVOOBJECTIVO
7100010001000
8-0.6789-0.6789-0.6789
90.10.10.1
10100010001000
110.390.390.39
127000%7000%7000%
13100010001000
14300020001000
Sheet1
Cell Formulas
RangeFormula
D14:F14D14=SUMINT(D5:D13)


Dear @Peter_SSs 👌

Hope you are ok.
Sorry for the delay.
Tested your suggestion however still not working for me. Wonder if is something about language translator...

What you think?
Thanks again my Friend.👍👍
 
Upvote 0
still not working for me.
In what way is it not working?

Are any of the results in post #11 incorrect for the sample data given?

Can you give some new sample data with XL2BB and tell us what result you got with the post #11 function and what result(s) you would want and why?
 
Upvote 0
In what way is it not working?

Are any of the results in post #11 incorrect for the sample data given?

Can you give some new sample data with XL2BB and tell us what result you got with the post #11 function and what result(s) you would want and why?

Dear @Peter_SSs

Just to show have the VBA code accordingly and the sample of data.
Wonder what is missing?
Im listen carefully.đŸ‘đŸ‘đŸ»
Thank you very much.


Function SomaInt(rng As Range) As Long
Dim c As Range
Dim v As Variant

For Each c In rng
v = c.Value
If IsNumeric(v) Then
If Int(v) = v And InStr(1, c.Text, "%") = 0 Then
SomaInt = SomaInt + v
End If
End If
Next c
End Function



FĂłrmula Principal para o Ficheiro VDF.xlsm
ABCDEFG
1
2
3SALES A
4PYG MTH %
5-3,143%
6OBJECTIVO
71000
8-0,6789
910%
101000
110,39
127000%
131000
14TOTAL#NOME?<= Expected Results
15
16
25-08-2024
Cell Formulas
RangeFormula
D14D14=SomaINT(D5:D13)
 
Upvote 0
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details.

I get a different result.
Try re-entering the formula in cell D14.

VBA Code:
Function SomaInt(rng As Range) As Long
  Dim c As Range
  Dim v As Variant

  For Each c In rng
    v = c.Value
    If IsNumeric(v) Then
      If Int(v) = v And InStr(1, c.Text, "%") = 0 Then
        SomaInt = SomaInt + v
      End If
    End If
  Next c
End Function

Lacan.xlsm
ABCDE
1
2
3SALES A
4PYG MTH %
5-3.143%
6OBJECTIVO
71000
8-0.6789
910%
101000
110.39
127000%
131000
14TOTAL3000<= Expected Results
Sheet2
Cell Formulas
RangeFormula
D14D14=SomaINT(D5:D13)
 
Upvote 0
Could be where you have the function code. Put it in a standard module.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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