+ Reply to Thread
Results 1 to 5 of 5

What's wrong with this

  1. #1
    Brad
    Guest

    What's wrong with this

    I'm trying to count the number of times a cell has a font size of 22, and it
    is giving me zero. I'm new to this stuff would appreciate any help.

    Function countbyfont(InRange As Range, _
    Whatfont As Integer, _
    Optional ofText As Boolean = False) As Long
    Dim Rng As Range
    Application.Volatile (True)

    For Each Rng In InRange.Cells
    If Cells.Font.Size = Whatfont Then
    countbyfont = countbyfont + 1
    End If
    Next Rng

    End Function


  2. #2
    Chip Pearson
    Guest

    Re: What's wrong with this

    Brad,

    Change
    If Cells.Font.Size = Whatfont Then
    to
    If Rng.Font.Size = Whatfont Then


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "Brad" <[email protected]> wrote in message
    news:[email protected]...
    > I'm trying to count the number of times a cell has a font size
    > of 22, and it
    > is giving me zero. I'm new to this stuff would appreciate any
    > help.
    >
    > Function countbyfont(InRange As Range, _
    > Whatfont As Integer, _
    > Optional ofText As Boolean = False) As Long
    > Dim Rng As Range
    > Application.Volatile (True)
    >
    > For Each Rng In InRange.Cells
    > If Cells.Font.Size = Whatfont Then
    > countbyfont = countbyfont + 1
    > End If
    > Next Rng
    >
    > End Function
    >




  3. #3
    Gary''s Student
    Guest

    RE: What's wrong with this

    Use:
    If Rng.Font.Size = Whatfont Then

    in stead of

    If Cells.Font.Size = Whatfont Then

    --
    Gary''s Student


    "Brad" wrote:

    > I'm trying to count the number of times a cell has a font size of 22, and it
    > is giving me zero. I'm new to this stuff would appreciate any help.
    >
    > Function countbyfont(InRange As Range, _
    > Whatfont As Integer, _
    > Optional ofText As Boolean = False) As Long
    > Dim Rng As Range
    > Application.Volatile (True)
    >
    > For Each Rng In InRange.Cells
    > If Cells.Font.Size = Whatfont Then
    > countbyfont = countbyfont + 1
    > End If
    > Next Rng
    >
    > End Function
    >


  4. #4
    Brad
    Guest

    Re: What's wrong with this

    Thank you that worked - are there other items that I should change to make
    this a better function?

    "Chip Pearson" wrote:

    > Brad,
    >
    > Change
    > If Cells.Font.Size = Whatfont Then
    > to
    > If Rng.Font.Size = Whatfont Then
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    > "Brad" <[email protected]> wrote in message
    > news:[email protected]...
    > > I'm trying to count the number of times a cell has a font size
    > > of 22, and it
    > > is giving me zero. I'm new to this stuff would appreciate any
    > > help.
    > >
    > > Function countbyfont(InRange As Range, _
    > > Whatfont As Integer, _
    > > Optional ofText As Boolean = False) As Long
    > > Dim Rng As Range
    > > Application.Volatile (True)
    > >
    > > For Each Rng In InRange.Cells
    > > If Cells.Font.Size = Whatfont Then
    > > countbyfont = countbyfont + 1
    > > End If
    > > Next Rng
    > >
    > > End Function
    > >

    >
    >
    >


  5. #5
    Dave Peterson
    Guest

    Re: What's wrong with this

    That looks fine (now).



    Brad wrote:
    >
    > Thank you that worked - are there other items that I should change to make
    > this a better function?
    >
    > "Chip Pearson" wrote:
    >
    > > Brad,
    > >
    > > Change
    > > If Cells.Font.Size = Whatfont Then
    > > to
    > > If Rng.Font.Size = Whatfont Then
    > >
    > >
    > > --
    > > Cordially,
    > > Chip Pearson
    > > Microsoft MVP - Excel
    > > Pearson Software Consulting, LLC
    > > www.cpearson.com
    > >
    > >
    > > "Brad" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I'm trying to count the number of times a cell has a font size
    > > > of 22, and it
    > > > is giving me zero. I'm new to this stuff would appreciate any
    > > > help.
    > > >
    > > > Function countbyfont(InRange As Range, _
    > > > Whatfont As Integer, _
    > > > Optional ofText As Boolean = False) As Long
    > > > Dim Rng As Range
    > > > Application.Volatile (True)
    > > >
    > > > For Each Rng In InRange.Cells
    > > > If Cells.Font.Size = Whatfont Then
    > > > countbyfont = countbyfont + 1
    > > > End If
    > > > Next Rng
    > > >
    > > > End Function
    > > >

    > >
    > >
    > >


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1