Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Marking my sub into a function i can use in excel

Make sure you put this in a standard Module (not a sheet o
ThisWorksheet).

Code
-------------------
Public Function countnonwhite(rInput As Range) as Single

Dim nonwhite As Single
nonwhite = 0
countnonwhite = 0

For Each c In ActiveSheet.Range(rInput)
If c.Interior.ColorIndex < -4142 Then nonwhite = nonwhite + 1
Next

countnonwhite = nonwhite

End Su
-------------------

Use it by entering =countnonwhite(A1:C100)



--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Marking my sub into a function i can use in excel


Hi there, and thanks for your help

I've got an error whereby it gives me a #value error in excel.

When i paste it into a sub and get it to display the results with a
msgbox it works perfectly.

Any ideas how i can get rid of the #value errors?


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Marking my sub into a function i can use in excel

Oops...

Public Function countnonwhite(rInput As Range) As Single

Dim c As Range
Dim nonwhite As Single

nonwhite = 0
countnonwhite = 0
Debug.Print rInput.Columns.Count

For Each c In rInput
If c.Interior.ColorIndex < -4142 Then nonwhite = nonwhite + 1
Next

countnonwhite = nonwhite

End Function

Since the rInput is already a range I shouldn't have used th
Range(rInput) statement.



--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Marking my sub into a function i can use in excel

Thanks for the help but 1 last question.

any idea how i get this to automatically update.

At the minute the result is static (i.e. it shows the result of the
formula the last time the formula was entered into the cell.

How do we get it to be like a '=sum' whereby if the range it evaluates
changes, so does the answer.

Thanks again for all your help,
Daren.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Marking my sub into a function i can use in excel

It should evaluate everytime the worksheet is calculated (including whe
enter a new value in a cell). If you want it to update anytime yo
change the color of a cell, I'm afraid you may be out of luck sinc
there is no event triggered when this happens.

You can add it to the Worksheet_SelectionChange event so that it wil
evaluate anytime a new cell is clicked. I.e.:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.Calculate
End Sub

If you are making the changes to the color via code, you can use th
Application.Calculate at the end of your code that makes the change
and get it to update.



--
Message posted from http://www.ExcelForum.com



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
Marking cells Mark Excel Discussion (Misc queries) 3 June 15th 09 03:55 PM
Marking page end lucy Excel Worksheet Functions 2 October 7th 08 12:04 AM
Excel 2007 Conditional Format: Marking Absences RJBohn3 Excel Discussion (Misc queries) 1 May 19th 07 06:03 PM
coloured marking Roland Burger New Users to Excel 5 April 14th 05 01:16 PM
Water marking Excel J. Joshi Excel Discussion (Misc queries) 1 February 10th 05 08:37 PM


All times are GMT +1. The time now is 11:26 AM.

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

About Us

"It's about Microsoft Excel"