Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 77
Default using vba to do a count for color cell

hi community

i do not really know how to use vba and this i only try myself but it did
not work..
can community please assist me more...

question:
i wanted to count cell for color and when to view some sites (was intro by
some in community) and i obtained this vba code..

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

and what i did was, I open my xls and activate the VB editor and at "Project
Window", I right-click the [sheet1] and choose view code,
from there, I wrote down the vba code according and
save the workbook

following the further instruction, at the worksheet, I do a fill "yellow"
into one cell, A1 thereafter
I used the code :

=CountYellow(A1:A5)

and i got a return #NAME

can someone kindly assist me in this :(

thanks alot to community

--
oldLearner57
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 709
Default using vba to do a count for color cell

Put the code in a module,

From your workbook right-click the workbook's icon and pick View Code. This
icon is at the top-left of the spreadsheet this will open the VBA editor, in
Project Explorer click on your workbook name, if you don't see it press CTRL
+ r to open the Project Explorer, then go to insert, module, and paste the
code in the window that opens on the right hand side, press Alt and Q to
close this window and go back to your workbook
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"tikchye_oldLearner57" wrote
in message ...
hi community

i do not really know how to use vba and this i only try myself but it did
not work..
can community please assist me more...

question:
i wanted to count cell for color and when to view some sites (was intro by
some in community) and i obtained this vba code..

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

and what i did was, I open my xls and activate the VB editor and at

"Project
Window", I right-click the [sheet1] and choose view code,
from there, I wrote down the vba code according and
save the workbook

following the further instruction, at the worksheet, I do a fill "yellow"
into one cell, A1 thereafter
I used the code :

=CountYellow(A1:A5)

and i got a return #NAME

can someone kindly assist me in this :(

thanks alot to community

--
oldLearner57



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default using vba to do a count for color cell

For quick fix here, instead of adding the code to the "Sheet" object
within the VBA Editor, add a new module and insert your code there.
That is, within the editor, do "Insert / Module" from the menu system,
then add your CountYellow() code. It shuold then work.

HTH
/ Tyla /


On Apr 11, 5:54 pm, tikchye_oldLearner57
wrote:
hi community

i do not really know how to use vba and this i only try myself but it did
not work..
can community please assist me more...

question:
i wanted to count cell for color and when to view some sites (was intro by
some in community) and i obtained this vba code..

Function CountYellow(MyRange As Range)
Dim iCount As Integer
Application.Volatile
iCount = 0
For Each cell In MyRange
If cell.Interior.ColorIndex = 6 Then
iCount = iCount + 1
End If
Next cell
CountYellow = iCount
End Function

and what i did was, I open my xls and activate the VB editor and at "Project
Window", I right-click the [sheet1] and choose view code,
from there, I wrote down the vba code according and
save the workbook

following the further instruction, at the worksheet, I do a fill "yellow"
into one cell, A1 thereafter
I used the code :

=CountYellow(A1:A5)

and i got a return #NAME

can someone kindly assist me in this :(

thanks alot to community

--
oldLearner57



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
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
can i use the color of a cell to count the different colerd cells scott Excel Discussion (Misc queries) 1 June 17th 06 01:49 AM
count by specific text color in range of cell Tii99 Excel Discussion (Misc queries) 2 April 4th 06 09:58 AM
Count if font color.. Murph Excel Discussion (Misc queries) 2 August 15th 05 10:45 PM
detect cell color and count it Maileen Excel Worksheet Functions 2 March 31st 05 11:51 PM


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