Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Uninvited function!!

Hi,
I am using the following code in a workbook ..which works fine by the way.
However, in another module of code which has no mention whatsoever of this
function..for some inexplicable reason the code calls this function and runs
through its code completley unnecessairly. This slows down the code in the
other module considerably and I want to resolve this.

As I said there is no mention at all of this function in my code so I have
not included it here. I cannot understand why it should be called. Can anyone
advise on this problem please.






Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Uninvited function!!

Hi Alan,

The line:

Application.Volatile True


will update each instance of the function when recalculation occurs.


---
Regards,
Norman



"Alan M" wrote in message
...
Hi,
I am using the following code in a workbook ..which works fine by the way.
However, in another module of code which has no mention whatsoever of this
function..for some inexplicable reason the code calls this function and
runs
through its code completley unnecessairly. This slows down the code in the
other module considerably and I want to resolve this.

As I said there is no mention at all of this function in my code so I have
not included it here. I cannot understand why it should be called. Can
anyone
advise on this problem please.






Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function



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
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Need to open the Function Arguments window from VBA for a user defined function. [email protected] Excel Programming 0 June 20th 06 03:53 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 10:31 PM.

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"