Sum Italics

  • Thread starter Thread starter Mathew P Bennett
  • Start date Start date
M

Mathew P Bennett

Good Evening All,
I have a ss (cash flow) where some of the values are entered as italics, and
the rest as normal.

I would like to be able to differenciate between the two when using a count
function, plus using the sum
function (but not together)
I thought of using an array, something like this, (or maybe a sumproduct)

ie SUM{(IF(A1:A10<>Italics,FALSE,A1:10))}

I feel sure some VBA will be needed.

Any help or pointers would be most appreciated.
Cheers
Mathew
 
Matthew,

Is there something about the italicized values that you can determine by other than visually looking
at them, or checking their font? Are they all negative, or greater than 100, or....

Anyway, lacking logic to select those values, a far better option would be to use another column,
and enter a value that could be checked, using a SUMIF / COUNTIF to get your values. Think of the
person who will inherit this workbook.....

HTH,
Bernie
MS Excel MVP
 
Thanks Bernie,
No, no difference between the values except italicized/normal (font, size,
colour all same), though could instruct the user tochange the font colour,
(instead of using italics), if that would make things easier.
I did not really get your point about using an extra column.

Cheers for your prompt reply.
I did think about using the colourfunction (which I like), but can I adapt
that for 'colourfontfunction' ?
Cheers
Mathew
 
My point about using the extra column is this: Say that you have values in column B, some of which
you want to count or sum. Instead of selecting, say, cell B10 and italicizing the cell, select cell
C10 and enter an X. Then use the formulas

=SUMIF(C1:C1000,"X",B1:B1000)
=COUNTIF(C1:C1000,"X")

You can use a VBA function:

Function SumI(rR As Range) As Double
Dim rC As Range
SumI = 0
For Each rC In rR
If rC.Font.Italic Then SumI = SumI + rC.Value
Next rC
End Function

used like

=SUMI(B2:B10)

But chaning a font doesn't trigger a re-calc, so you would need to force a re-calc for this to work.


HTH,
Bernie
MS Excel MVP
 
Press Alt + F11 to open the Visual Basic Editor.

Click INSERT on the menu and select MODULE.

In the new module enter the text between the lines of dashes
------------------------------------------------------------------------------------------
Function SumItalics(ValueRange As Range) As Double

Dim dblRetVal As Double
Dim l As Long

Application.Volatile

For l = 1 To ValueRange.Cells.Count
If ValueRange.Cells(l).Font.Italic = True Then
dblRetVal = dblRetVal + ValueRange.Cells(l)
End If
Next l

SumItalics = dblRetVa
------------------------------------------------------------------------------------------

To use it enter the function as you would any other function:

=SumItalics(A1:A10)

The press enter.

Hope this helps.
End Function
 
Thanks Kevin,
This a nice useful code & function.
It works for wha I want.
Hopefully I will be able to adapt it 'count' also.
Cheers again
Mathew
 
Here's your count verion:


Function CountItalics(ValueRange As Range) As Double


Dim lngItalics As Long
Dim l As Long

Application.Volatile

For l = 1 To ValueRange.Cells.Count
If ValueRange.Cells(l).Font.Italic = True Then
lngItalics = lngItalics + 1
End If
Next l

CountItalics = lngItalics

End Function
 
Kevin, Cheers, Most Appreciated.
Thank you
Mathew
Kevin B said:
Here's your count verion:


Function CountItalics(ValueRange As Range) As Double


Dim lngItalics As Long
Dim l As Long

Application.Volatile

For l = 1 To ValueRange.Cells.Count
If ValueRange.Cells(l).Font.Italic = True Then
lngItalics = lngItalics + 1
End If
Next l

CountItalics = lngItalics

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top