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
199
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

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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

Forum statistics

Threads
1,221,501
Messages
6,160,177
Members
451,629
Latest member
MNexcelguy19

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