Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
See http://www.xldynamic.com/source/xld.ColourCounter.html for a working
solution -- HTH Bob Phillips (remove nothere from email address if mailing direct) "apx2001" wrote in message ... i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub test()
Dim c As Range Dim i As Long For Each c In ActiveSheet.UsedRange If c.Interior.ColorIndex < -4142 Then i = i + 1 End If Next MsgBox i & " cells with a colour format", , _ "counting coloured cells" End Sub RBS "apx2001" wrote in message ... i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() thank you for your help and the reference! best, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This gives more information:
Sub test() Dim c As Range Dim i As Long Dim n As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & arrColours(n, 2) End If Next MsgBox i & " cells with a colour format" & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------" & vbCrLf & _ strColours, , _ "counting coloured cells" End Sub RBS "RB Smissaert" wrote in message ... Sub test() Dim c As Range Dim i As Long For Each c In ActiveSheet.UsedRange If c.Interior.ColorIndex < -4142 Then i = i + 1 End If Next MsgBox i & " cells with a colour format", , _ "counting coloured cells" End Sub RBS "apx2001" wrote in message ... i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Added a counter, just for in case you were dealing with a very large range.
Sub CountColours() Dim c As Range Dim i As Long Dim n As Long Dim x As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String Dim lCellCount As Long lCellCount = ActiveSheet.UsedRange.Cells.Count For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If x = x + 1 If x Mod lCellCount \ 100 = 0 Then Application.StatusBar = " " & _ Round((x / lCellCount), 2) _ * 100 & _ " % done" End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & _ arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & _ arrColours(n, 2) End If Next MsgBox i & " cells with a colour format" & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------" & vbCrLf & _ strColours, , _ "counting coloured cells" Application.StatusBar = False End Sub RBS "RB Smissaert" wrote in message ... This gives more information: Sub test() Dim c As Range Dim i As Long Dim n As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & arrColours(n, 2) End If Next MsgBox i & " cells with a colour format" & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------" & vbCrLf & _ strColours, , _ "counting coloured cells" End Sub RBS "RB Smissaert" wrote in message ... Sub test() Dim c As Range Dim i As Long For Each c In ActiveSheet.UsedRange If c.Interior.ColorIndex < -4142 Then i = i + 1 End If Next MsgBox i & " cells with a colour format", , _ "counting coloured cells" End Sub RBS "apx2001" wrote in message ... i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Fixed a division by zero bug:
Sub CountColours() Dim c As Range Dim i As Long Dim n As Long Dim x As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String Dim lCellCount As Long lCellCount = ActiveSheet.UsedRange.Cells.Count For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If If lCellCount 10000 Then x = x + 1 If x Mod lCellCount \ 100 = 0 Then Application.StatusBar = " " & _ Round((x / lCellCount), 2) _ * 100 & _ " % done" End If End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & _ arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & _ arrColours(n, 2) End If Next MsgBox "Used range with " & lCellCount & " cells." & _ vbCrLf & _ i & " cells with a colour format." & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------------------" & _ vbCrLf & _ strColours, , _ "counting coloured cells" If lCellCount 10000 Then Application.StatusBar = False End If End Sub RBS "RB Smissaert" wrote in message ... Added a counter, just for in case you were dealing with a very large range. Sub CountColours() Dim c As Range Dim i As Long Dim n As Long Dim x As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String Dim lCellCount As Long lCellCount = ActiveSheet.UsedRange.Cells.Count For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If x = x + 1 If x Mod lCellCount \ 100 = 0 Then Application.StatusBar = " " & _ Round((x / lCellCount), 2) _ * 100 & _ " % done" End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & _ arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & _ arrColours(n, 2) End If Next MsgBox i & " cells with a colour format" & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------" & vbCrLf & _ strColours, , _ "counting coloured cells" Application.StatusBar = False End Sub RBS "RB Smissaert" wrote in message ... This gives more information: Sub test() Dim c As Range Dim i As Long Dim n As Long Dim vIndex Dim nMax As Long Dim arrColours(1 To 255, 1 To 2) As Long Dim strColours As String For Each c In ActiveSheet.UsedRange vIndex = c.Interior.ColorIndex For n = 1 To nMax + 1 If vIndex = arrColours(n, 1) Then arrColours(n, 2) = arrColours(n, 2) + 1 If n nMax Then nMax = n End If Exit For End If If arrColours(n, 1) = 0 Then arrColours(n, 1) = vIndex arrColours(n, 2) = 1 nMax = n End If Next If vIndex 0 Then i = i + 1 End If Next For n = 1 To nMax If n 1 Then strColours = strColours & vbCrLf & _ arrColours(n, 1) & vbTab & arrColours(n, 2) Else strColours = arrColours(n, 1) & vbTab & arrColours(n, 2) End If Next MsgBox i & " cells with a colour format" & _ vbCrLf & vbCrLf & _ "index" & vbTab & "count" & vbCrLf & _ "-----------------------" & vbCrLf & _ strColours, , _ "counting coloured cells" End Sub RBS "RB Smissaert" wrote in message ... Sub test() Dim c As Range Dim i As Long For Each c In ActiveSheet.UsedRange If c.Interior.ColorIndex < -4142 Then i = i + 1 End If Next MsgBox i & " cells with a colour format", , _ "counting coloured cells" End Sub RBS "apx2001" wrote in message ... i have been trying to figure out a macro that counts cells with an interior color other than white and display the results in a message box. any suggestions are highly appreciated! thanks, johannes -- apx2001 ------------------------------------------------------------------------ apx2001's Profile: http://www.excelforum.com/member.php...o&userid=32306 View this thread: http://www.excelforum.com/showthread...hreadid=520593 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do you count colored cells? | Excel Worksheet Functions | |||
count colored cells? | Excel Worksheet Functions | |||
How to Count only Colored cells | Excel Programming | |||
Count non-colored cells | Excel Discussion (Misc queries) | |||
Count or sum colored cells | Excel Worksheet Functions |