Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
i did something wrong Roy Excel Discussion (Misc queries) 3 October 9th 06 10:45 PM
Min Max What's Wrong? shep Excel Worksheet Functions 4 October 4th 06 09:46 PM
Getting wrong value due to ref? jesmin Excel Discussion (Misc queries) 2 March 16th 06 02:12 AM
where does it go wrong? minostrada Excel Programming 4 November 29th 05 07:40 AM


All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"