Adding numbers based on font size

%3CLINGO-SUB%20id%3D%22lingo-sub-1649092%22%20slang%3D%22en-US%22%3EAdding%20numbers%20based%20on%20font%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1649092%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20list%20of%20bond%20payments.%20The%20ones%20that%20come%20in%20on%20the%20first%20of%20the%20month%20are%20in%20font%20size%2010....the%20ones%20that%20pay%20on%20the%2015th%20are%20in%20font%20size%2012.%26nbsp%3BIs%20there%20a%20way%20for%20me%20to%20create%20a%20formula%20that%20will%20add%20the%20values%20of%20only%20one%20particular%20font%20size%3F%26nbsp%3B%20Thanks%20for%20any%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1649092%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1649988%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20numbers%20based%20on%20font%20size%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1649988%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F787362%22%20target%3D%22_blank%22%3E%40KevinG44%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EYou%20can%20use%20the%20following%20VBA%20code.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20count_font()%0ADim%20i%20As%20Integer%0ADim%20calc15%20As%20Integer%0ADim%20font15%20As%20Integer%0ADim%20j%20As%20Integer%0ADim%20calc10%20As%20Integer%0ADim%20font10%20As%20Integer%0A%0Acalc%20%3D%200%0A'loops%20through%20the%20cells%20in%20column%201%0AFor%20i%20%3D%201%20To%208%0A'gets%20the%20font%20size%0Afont15%20%3D%20Range(Cells(i%2C%201)%2C%20_%0ACells(i%2C%201)).Font.Size%0AIf%20font15%20%3D%2015%20Then%0Acalc15%20%3D%20calc15%20%2B%20Cells(i%2C%201).Value%0AEnd%20If%0ANext%20i%0ACells(2%2C%203)%20%3D%20%22Total%20for%20Font%2015%20-%20%22%20%26amp%3B%20calc15%0A%0Acalc10%20%3D%200%0A'loops%20through%20the%20cells%20in%20column%201%0AFor%20j%20%3D%201%20To%208%0A'gets%20the%20font%20size%0Afont10%20%3D%20Range(Cells(j%2C%201)%2C%20_%0ACells(j%2C%201)).Font.Size%0AIf%20font10%20%3D%2010%20Then%0Acalc10%20%3D%20calc10%20%2B%20Cells(j%2C%201).Value%0AEnd%20If%0ANext%20j%0ACells(3%2C%203)%20%3D%20%22Total%20for%20Font%2010%20-%20%22%20%26amp%3B%20calc10%0A%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EYou%20will%20need%20to%20adjust%20it%20for%20where%20your%20data%20is%20actually%20written%20in%20your%20spreadsheet%20and%20where%20you%20want%20the%20output%20to%20go.%20Let%20me%20know%20if%20you%20need%20a%20hand%20with%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I have a list of bond payments. The ones that come in on the first of the month are in font size 10....the ones that pay on the 15th are in font size 12. Is there a way for me to create a formula that will add the values of only one particular font size?  Thanks for any help.

2 Replies

Hi @KevinG44,

You can use the following VBA code.

Private Sub count_font()
Dim i As Integer
Dim calc15 As Integer
Dim font15 As Integer
Dim j As Integer
Dim calc10 As Integer
Dim font10 As Integer

calc = 0
'loops through the cells in column 1
For i = 1 To 8
'gets the font size
font15 = Range(Cells(i, 1), _
Cells(i, 1)).Font.Size
If font15 = 15 Then
calc15 = calc15 + Cells(i, 1).Value
End If
Next i
Cells(2, 3) = "Total for Font 15 - " & calc15

calc10 = 0
'loops through the cells in column 1
For j = 1 To 8
'gets the font size
font10 = Range(Cells(j, 1), _
Cells(j, 1)).Font.Size
If font10 = 10 Then
calc10 = calc10 + Cells(j, 1).Value
End If
Next j
Cells(3, 3) = "Total for Font 10 - " & calc10


End Sub

You will need to adjust it for where your data is actually written in your spreadsheet and where you want the output to go. Let me know if you need a hand with that.

 

Not without using vba to write a procedure (or a user defined function that you could use in the worksheet).

Could you use a conditional sum function to test the day of the date and sum amounts based on whether it is 1 or 15?

Say the date is in column A and the amount is in B:
=SUMPRODUCT(--(DAY(A1:A10)=1),B1:B10)
=SUMPRODUCT(--(DAY(A1:A10)=15),B1:B10)