Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Kam
 
Posts: n/a
Default Count by color using VBA in Microsoft Excel

I am having the following formula to count on the basis of colour. For example
Total 12 cell out of which Red - 1, Yellow - 5 & Green - 6 so by using this
formula this should give proper count as mentioned above.

I need you assistance as i have never used macro using VBA in Microsoft
Excel.

Could you please guide me (Step by Step) how to run this macro in excel.

Appreciate your kind assistance.

Thanks in advance.
Kamlesh

Function CountByColor(InputRange As Range, ColorRange as Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex Then
TempCount = TempCount + 1
End If
Next cl
Set cl = Nothing
CountByColor = TempCount
End Function


  #2   Report Post  
Rowan Drummond
 
Posts: n/a
Default Count by color using VBA in Microsoft Excel

Hi Kam

Copy the code to the clipboard.
In Excel press Alt+F11.
This will open the Visual Basic Editor (VBE).
From the menus select InsertModule.
Paste the code into the new module (major white part on right of screen).
Click on the Excel icon (Left most button on toolbar) to return to Excel.
In the cell that you want your result type the formula:
=countbycolor(D4:D16,D4)
Where D4:D16 is the range of cells you want to check and D4 is a single
cell which is set to the colour you are wanting to count. This does not
need to be in the first range.

Hope this helps
Rowan

Kam wrote:
I am having the following formula to count on the basis of colour. For example
Total 12 cell out of which Red - 1, Yellow - 5 & Green - 6 so by using this
formula this should give proper count as mentioned above.

I need you assistance as i have never used macro using VBA in Microsoft
Excel.

Could you please guide me (Step by Step) how to run this macro in excel.

Appreciate your kind assistance.

Thanks in advance.
Kamlesh

Function CountByColor(InputRange As Range, ColorRange as Range) As Long
Dim cl As Range, TempCount As Long, ColorIndex As Integer
ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
TempCount = 0
For Each cl In InputRange.Cells
If cl.Interior.ColorIndex = ColorIndex Then
TempCount = TempCount + 1
End If
Next cl
Set cl = Nothing
CountByColor = TempCount
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
Export to Microsoft Excel from IE AndreasSjoberg Excel Discussion (Misc queries) 2 October 19th 05 02:41 PM
import payees from Excel into Microsoft Money 2006 rickramz Excel Discussion (Misc queries) 0 October 17th 05 11:14 PM
Excell VS Office Cathyandrea Excel Discussion (Misc queries) 1 September 19th 05 07:02 AM
Microsoft Access Report into Excel Spreadsheet zeebyrd Excel Discussion (Misc queries) 1 February 27th 05 12:36 AM
How can I use count function in excel where I have several criter. Princess V Excel Worksheet Functions 14 November 3rd 04 10:18 PM


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