Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default countbycolor counts all cells in a merged cell


I have multiple merged cells, each with any of 3 possible colors. When
I use the countbycolor module, it counts all the cells in the merge
area. What I want is to count the merge areas, not the individual
cells, by color. Any hints?


--
dsamson
------------------------------------------------------------------------
dsamson's Profile: http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default countbycolor counts all cells in a merged cell

what countbycolour module?

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"dsamson" wrote in
message ...

I have multiple merged cells, each with any of 3 possible colors. When
I use the countbycolor module, it counts all the cells in the merge
area. What I want is to count the merge areas, not the individual
cells, by color. Any hints?


--
dsamson
------------------------------------------------------------------------
dsamson's Profile:

http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default countbycolor counts all cells in a merged cell

Everyone is supposed to know where you got the countbycolor module?

If you post the code, then perhaps someone can advise how to modify it.

--
Regards,
Tom Ogilvy

"dsamson" wrote in
message ...

I have multiple merged cells, each with any of 3 possible colors. When
I use the countbycolor module, it counts all the cells in the merge
area. What I want is to count the merge areas, not the individual
cells, by color. Any hints?


--
dsamson
------------------------------------------------------------------------
dsamson's Profile:

http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default countbycolor counts all cells in a merged cell

If I understand right then this will do what you want:

Sub test()

Dim rng As Range
Dim rngMergeCells As Range
Dim collMergeRanges As Collection
Dim n As Long
Dim i As Long
Dim collCount
Dim bInMerge As Boolean
Dim btColorIndex As Byte

btColorIndex = 3

Set collMergeRanges = New Collection

For Each rng In Range(Cells(1), Cells(10, 10)).Cells
If rng.MergeCells Then
collCount = collMergeRanges.Count
If collCount 0 Then
bInMerge = False
For i = 1 To collCount
If Not Intersect(collMergeRanges(i), rng) Is Nothing Then
'in merged area, so has been dealt with already
bInMerge = True
Exit For
End If
Next
End If
If bInMerge = False Then
'part of merged cells, but not been dealth with yet
If rng.Interior.ColorIndex = btColorIndex Then
n = n + 1
End If
collMergeRanges.Add rng.MergeArea
End If
Else
'not part of merged cells
If rng.Interior.ColorIndex = btColorIndex Then
n = n + 1
End If
End If
Next

MsgBox n, , _
"number of single cells or merged ranges with colorindex " &
btColorIndex

End Sub


RBS


"dsamson" wrote in
message ...

I have multiple merged cells, each with any of 3 possible colors. When
I use the countbycolor module, it counts all the cells in the merge
area. What I want is to count the merge areas, not the individual
cells, by color. Any hints?


--
dsamson
------------------------------------------------------------------------
dsamson's Profile:
http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default countbycolor counts all cells in a merged cell


The code I was working with is:

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
If cl.MergeCells = True Then
Next cl
End If

Next cl
Set cl = Nothing
CountByColor = TempCount
End Sub

This works well, but I need it count a merged cell as a single cell,
vice the number of cells merged.

Thanks.


--
dsamson
------------------------------------------------------------------------
dsamson's Profile: http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default countbycolor counts all cells in a merged cell

but I need it count a merged cell as a single cell

Yes, and that is what my posted sub does.

RBS


dsamson wrote:
The code I was working with is:

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
If cl.MergeCells = True Then
Next cl
End If

Next cl
Set cl = Nothing
CountByColor = TempCount
End Sub

This works well, but I need it count a merged cell as a single cell,
vice the number of cells merged.

Thanks.


--
dsamson
------------------------------------------------------------------------
dsamson's Profile: http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default countbycolor counts all cells in a merged cell


Keep in mind I have no idea what I'm doing. My original code was
something I found on the web. Do I replace my code with yours in its
entirety, or is it something I place within my original? In the
latter, my result is a "#NAME?"


--
dsamson
------------------------------------------------------------------------
dsamson's Profile: http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default countbycolor counts all cells in a merged cell

You will have to explain what exactly you are trying to do.
We can probably forget about that module you are talking about as it doesn't
do what you want.
The code I posted is a Sub that will run by it-self, so no, don't place it
in whatever other code you have.
I don't think this is a complicated problem, but your explanation just isn't
clear at all.

RBS

"dsamson" wrote in
message ...

Keep in mind I have no idea what I'm doing. My original code was
something I found on the web. Do I replace my code with yours in its
entirety, or is it something I place within my original? In the
latter, my result is a "#NAME?"


--
dsamson
------------------------------------------------------------------------
dsamson's Profile:
http://www.excelforum.com/member.php...o&userid=35528
View this thread: http://www.excelforum.com/showthread...hreadid=552955


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
Cell names of merged cells DLB Excel Discussion (Misc queries) 1 April 15th 10 12:06 AM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
=countbycolor anomalies Bilbert Excel Worksheet Functions 3 December 7th 06 02:18 PM
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 01:56 PM.

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"