Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA function reading all cells as -4142

Hi,

I'm counting the number of Light Turquoise cells in a
column on a worksheet, I know that my function works, but
it is picking up all the cell fill colors as -4142, when i
know that they are 34. Is there some option I have to turn
on to get the functions to read formatted cells?

Or am I doing something else wrong?

My function:

Function CountBlueCells(InputRange As Range) As Long
Dim cl As Range
Dim NumberOfBlueCells As Integer
Application.Volatile
On Error Resume Next ' ignore any errors
For Each cl In InputRange
If (cl.Interior.ColorIndex = 34) Then
NumberOfBlueCells = NumberOfBlueCells + 1
End If
Next cl
On Error GoTo 0
CountBlueCells = NumberOfBlueCells
End Function

cheers,
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default VBA function reading all cells as -4142

As a guess, and assuming you're passng a valid range, are the cells
colored using Conditional Formatting?

If so, VBA has no easy way of determining whether CF is applied or
not. Instead, use the same condition that you used in the CF
criterion.

In article ,
"Chris J." wrote:

I'm counting the number of Light Turquoise cells in a
column on a worksheet, I know that my function works, but
it is picking up all the cell fill colors as -4142, when i
know that they are 34. Is there some option I have to turn
on to get the functions to read formatted cells?

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
Reading Cells from One Worksheet in another Mike Setting up and Configuration of Excel 2 July 19th 07 08:26 PM
Reading Cells In another worksheet mike Excel Discussion (Misc queries) 1 June 7th 07 03:09 PM
Reading Cells is the same workbook different tab Mike Excel Discussion (Misc queries) 1 June 7th 07 03:08 PM
Reading Cell Function??? roy.okinawa Excel Worksheet Functions 2 December 1st 05 11:29 PM
reading cells from a spreadsheet using VB Bob Kilmer Excel Programming 0 August 1st 03 01:37 PM


All times are GMT +1. The time now is 10:04 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"