Note: The other languages of the website are Google-translated. Back to English
로그인  \/ 
x
or
x
REGISTER  \/ 
x

or

Excel에서 배경색을 기준으로 셀 수를 계산하고 합계하는 방법은 무엇입니까?

빨강, 녹색, 파랑 등과 같이 배경색이 다른 셀 범위가 있다고 가정하지만 이제 해당 범위에서 특정 배경색을 가진 셀 수를 계산하고 동일한 특정 색상을 가진 색상 셀을 합산해야합니다. . Excel에는 색상 셀의 합계와 개수를 계산하는 직접적인 공식이 없습니다. 여기서는이 문제를 해결하는 몇 가지 방법을 소개합니다.


필터 및 SUBTOTAL로 색이 지정된 셀 수 및 합계

아래 스크린 샷과 같이 과일 판매 테이블이 있다고 가정하고 Amount 열의 색상 셀을 계산하거나 합산합니다. 이 상황에서 Amount 열을 색상별로 필터링 한 다음 Excel에서 쉽게 SUBTOTAL 함수로 필터링 된 색상 셀을 계산하거나 합계 할 수 있습니다.

1. SUBTOTAL 함수를 입력하려면 빈 셀을 선택하십시오.

  1. 배경색이 같은 모든 셀을 계산하려면 수식을 입력하세요. = SUBTOTAL (102, E2 : E20);
  2. 배경색이 같은 모든 셀을 합하려면 수식을 입력하십시오. = SUBTOTAL (109, E2 : E20);


주의 사항: 두 수식에서 E2 : E20은 색상이 지정된 셀이 포함 된 Amount 열이며 필요에 따라 변경할 수 있습니다.

2. 표의 헤더를 선택하고 데이터 > FILTER. 스크린 샷보기 :

3. 필터 아이콘을 클릭하십시오.  금액 열의 머리글 셀에서 색상별로 필터 그리고 당신이 연속적으로 계산할 지정된 색상. 스크린 샷보기 :

필터링 후 양 열의 필터링 된 모든 색상 셀을 자동으로 계산하고 합산하는 두 SUBTOTAL 수식. 스크린 샷보기 :

주의 사항:이 방법을 사용하려면 계산할 색상 셀이 필요하거나 합계가 같은 열에 있어야합니다.

한 번의 클릭으로 Excel에서 색상 셀 계산, 합계 및 평균화

훌륭한 색상으로 계산 특징 Excel 용 Kutools, Excel에서 한 번의 클릭으로 지정된 채우기 색상 또는 글꼴 색상으로 셀 수, 합계 및 평균을 빠르게 계산할 수 있습니다. 또한이 기능은 채우기 색상 또는 글꼴 색상으로 셀의 최대 및 최소 값을 알아냅니다. 30 일 전체 기능 무료 평가판!
색상 2 별 광고 수

Excel 용 Kutools -300 개 이상의 Excel 용 편리한 도구가 포함되어 있습니다. 30 일 전체 기능 무료 평가판, 신용 카드 필요 없음! 이제 그것을 잡아

GET.CELL 함수로 색이 지정된 셀 수 또는 합계

이 방법에서는 GET.CELL 함수로 명명 된 범위를 만들고 셀의 색상 코드를 가져온 다음 Excel에서 색상 코드로 쉽게 계산하거나 합계합니다. 다음과 같이하십시오 :

1. 딸깍 하는 소리 방식 > 이름 정의. 스크린 샷보기 :

2. 새 이름 대화 상자에서 아래 스크린 샷과 같이 수행하십시오.
(1) 이름 상자에 이름을 입력합니다.
(2) 공식 입력 = GET.CELL (38, Sheet4! $ E2) 참조 대상 상자 (주의: 공식에서 38 셀 코드 반환을 의미하고 Sheet4! $ E2 테이블 데이터에 따라 변경해야하는 열 머리글을 제외한 금액 열의 첫 번째 셀입니다.)
(3) OK 버튼을 클릭합니다.

3. 이제 원래 테이블에 새 색상 열을 추가하십시오. 다음으로 수식 입력 = NumColor 을 클릭하고 자동 완성 핸들을 드래그하여 색상 열의 다른 셀에 수식을 적용합니다. 스크린 샷보기 :
주의 사항: 공식에서 숫자 색상 처음 두 단계에서 지정한 명명 된 범위입니다. 설정 한 지정된 이름으로 변경해야합니다.

이제 금액 열에있는 각 셀의 색상 코드가 색상 열에 반환됩니다. 스크린 샷보기 :

4. 활성 워크 시트의 빈 범위에 채우기 색상을 복사하여 나열하고 아래 스크린 샷과 같이 그 옆에 수식을 입력합니다.
A. 색상별로 셀 수를 계산하려면 공식을 입력하십시오. = COUNTIF ($ F $ 2 : $ F $ 20, NumColor);
B. 색상별로 셀을 합하려면 공식을 입력하십시오. = SUMIF ($ F $ 2 : $ F $ 20, NumColor, $ E $ 2 : $ E $ 20).

주의 사항: 두 공식 모두에서 $ F $ 2 : $ F $ 20 색상 열입니다. 숫자 색상 지정된 명명 된 범위입니다. $ E $ 2 : $ E $ 20 금액 열이며 필요에 따라 변경할 수 있습니다.

이제 Amount 열의 셀이 계산되고 채우기 색상으로 합산되는 것을 볼 수 있습니다.


사용자 정의 함수로 특정 채우기 색상을 기준으로 셀 수 및 합계

컬러 셀이 아래 스크린 샷과 같이 범위에 흩어져 있다고 가정하면 위의 두 방법 모두 컬러 셀을 계산하거나 합산 할 수 없습니다. 여기서이 방법은 문제를 해결하기 위해 VBA를 도입합니다.

1. 누르고 ALT + F11 키가 열립니다. 응용 프로그램 용 Microsoft Visual Basic 창.

2. 딸깍 하는 소리 끼워 넣다 > 모듈을 클릭하고 모듈 창에 다음 코드를 붙여 넣습니다.

VBA : 배경색을 기준으로 셀 수 및 합계 :

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function

3. 그런 다음 코드를 저장하고 다음 공식을 적용합니다.
A. 색상이 지정된 셀 수 : = colorfunction (A, B : C, FALSE)
B. 색상 셀 합계 : = colorfunction (A, B : C, TRUE)

참고 : 위의 공식에서 A 개수와 합계를 계산하려는 특정 배경색이있는 셀입니다. 기원전 개수와 합계를 계산하려는 셀 범위입니다.

4. 예를 들어 다음 스크린 샷을 찍고 공식을 입력합니다.= colorfunction (A1, A1 : D11, FALSE) 노란색 세포를 계산합니다. 그리고 공식을 사용하십시오 = colorfunction (A1, A1 : D11, TRUE) 노란색 셀을 합산합니다. 스크린 샷보기 :

5. 다른 색상의 셀을 계산하고 합하려면 4 단계를 반복하십시오. 그러면 다음 결과가 나타납니다.


Kutools 함수를 사용하여 특정 채우기 색상을 기반으로 셀 수 및 합계

Excel 용 Kutools는 Excel 사용자가 특별한 계산을 할 수 있도록 몇 가지 유용한 기능을 지원합니다. 셀 배경색으로 계산, 글꼴 색상으로 합계 등을 말합니다.

Excel 용 Kutools -300 개 이상의 Excel 용 편리한 도구가 포함되어 있습니다. 30 일 전체 기능 무료 평가판, 신용 카드 필요 없음! 지금 무료 평가판!

1. 계산 결과를 배치 한 빈 셀을 선택하고 Kutools > Kutools 기능 > 통계 및 수학 > COUNTBYCELLCOLOR. 스크린 샷보기 :

2. 함수 인수 대화 상자에서 색상 셀을 계산할 범위를 지정하십시오. 참고 상자에서 지정된 배경색으로 채워진 셀을 선택합니다. Color_index_nr 상자를 클릭하고 OK 단추. 스크린 샷보기 :

배송 시 요청 사항:
(1) 지정된 Kutools 함수를 입력 할 수도 있습니다. = COUNTBYCELLCOLOR ($ A $ 1 : $ E $ 20, G2)  빈 셀 또는 수식 표시 줄에서 직접 계산 결과를 얻습니다.
(2) 클릭 Kutools > Kutools 기능 > 통계 및 수학 > SUMBYCELLCOLOR 또는 입력 = SUMBYCELLCOLOR ($ A $ 1 : $ E $ 20, G2) 빈 셀에서 직접 지정된 배경색을 기준으로 셀을 합산합니다.
을 적용 COUNTBYCELLCOLOR SUMBYCELLCOLOR 각 배경색에 대해 개별적으로 기능을 수행하고 아래 스크린 샷과 같은 결과를 얻을 수 있습니다.

Kutools 기능 Excel 사용자가 쉽게 계산할 수 있도록 도와주는 여러 가지 기본 제공 함수가 포함되어 있습니다. 개수 / 합계 / 평균 보이는 셀, 셀 색상 별 개수 / 합, 글꼴 색상 별 개수 / 합계, 문자 수, 굵은 글꼴로 계산무료 평가판을 받으십시오!


Excel 용 Kutools를 사용하여 특정 채우기 색상을 기반으로 셀 수 및 합계

위의 사용자 정의 함수를 사용하면 수식을 하나씩 입력해야합니다. 다른 색상이 많으면이 방법은 지루하고 시간이 많이 걸립니다. 하지만 만약 당신이 Excel 용 Kutools색상으로 계산 유틸리티를 사용하면 컬러 셀에 대한 보고서를 빠르게 생성 할 수 있습니다. 색상이 지정된 셀을 계산하고 합산 할 수있을뿐만 아니라 색상 범위의 평균, 최대 및 최소 값도 얻을 수 있습니다.

Excel 용 Kutools -300 개 이상의 Excel 용 편리한 도구가 포함되어 있습니다. 30 일 전체 기능 무료 평가판, 신용 카드 필요 없음! 지금 무료 평가판!

1. 사용할 범위를 선택하고 쿠툴즈 플러스 > 색상으로 계산, 스크린 샷 참조 :

2. 그리고에 색상으로 계산 대화 상자에서 아래 스크린 샷과 같이 수행하십시오.
(1) 선택 표준 서식 인사말 색상 방법 드롭 다운 목록;
(2) 선택 배경 인사말 개수 유형 드롭 다운 목록.
(3) 보고서 생성 버튼을 클릭합니다.

주의 사항: 특정 조건부 서식 색상으로 색상 셀을 계산하고 합하려면 다음을 선택하십시오. 조건부 서식 인사말 색상 방법 위의 대화 상자에서 드롭 다운 목록을 선택하거나 표준 및 조건부 서식 드롭 다운 목록에서 지정된 색상으로 채워진 모든 셀을 계산합니다.

이제 통계가 포함 된 새 통합 문서를 얻을 수 있습니다. 스크린 샷보기 :

그리고, 색상으로 계산 기능은 배경색 또는 글꼴 색상으로 셀 (개수, 합계, 평균, 최대 등)을 계산합니다. 무료 평가판을 받으십시오!


관련 기사 :


데모 : 배경, 조건부 서식 색상을 기반으로 셀 수 및 합계 :


Excel 용 Kutools 300 개 이상의 Excel 용 편리한 도구가 포함되어 있으며 30 일 이내에 제한없이 사용해 볼 수 있습니다. 지금 다운로드 및 무료 평가판!

최고의 사무 생산성 도구

Excel 용 Kutools는 대부분의 문제를 해결하고 생산성을 80 % 향상시킵니다.

  • 재사용: 빠르게 삽입 복잡한 공식, 차트 그리고 이전에 사용한 모든 것; 셀 암호화 암호로; 메일 링리스트 생성 이메일 보내기 ...
  • 슈퍼 포뮬러 바 (여러 줄의 텍스트와 수식을 쉽게 편집 할 수 있습니다.) 레이아웃 읽기 (많은 수의 셀을 쉽게 읽고 편집합니다.) 필터링 된 범위에 붙여 넣기...
  • 셀 / 행 / 열 병합 데이터 손실없이; 셀 내용 분할; 중복 행 / 열 결합... 중복 셀 방지; 범위 비교...
  • 중복 또는 고유 선택 행; 빈 행 선택 (모든 셀이 비어 있음); 슈퍼 찾기 및 퍼지 찾기 많은 통합 문서에서; 무작위 선택 ...
  • 정확한 사본 수식 참조를 변경하지 않고 여러 셀; 참조 자동 생성 여러 시트에; 글 머리 기호 삽입, 확인란 등 ...
  • 텍스트 추출, 텍스트 추가, 위치 별 제거, 공간 제거; 페이징 부분합을 만들고 인쇄합니다. 셀 내용과 주석 간 변환...
  • 슈퍼 필터 (다른 시트에 필터 구성표 저장 및 적용) 고급 정렬 월 / 주 / 일, 빈도 등 특수 필터 굵은 기울임 꼴로 ...
  • 통합 문서와 워크 시트 결합; 키 열을 기반으로 테이블 병합; 데이터를 여러 시트로 분할; xls, xlsx 및 PDF 일괄 변환...
  • 300 개 이상의 강력한 기능. Office / Excel 2007-2019 및 365를 지원합니다. 모든 언어를 지원합니다. 기업 또는 조직에 쉽게 배포 할 수 있습니다. 전체 기능 30 일 무료 평가판. 60 일 환불 보장.
kte 탭 201905

Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50 % 향상시키고 매일 수백 번의 마우스 클릭을 줄입니다!
officetab 하단
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Dusty · 1 years ago
    Is there a way to count different color backgrounds from conditional formatting? The current code as of 7/14/2020 counts them all as default yellow or not at all.
    • To post as a guest, your comment is unpublished.
      kellytte · 11 months ago
      Hi Dusty,
      You can try the Count by Color feature of Kutools for Excel. This feature will help you quickly calculate (count, sum, average, etc.) cells by cell background color or font color, no matter they are formatted by conditional formatting or solidly format.
  • To post as a guest, your comment is unpublished.
    Dennis · 1 years ago
    Did anyone find a solution to auto-refresh? I have to manually refresh for it to update. Otherwise, it works great!
    • To post as a guest, your comment is unpublished.
      kellytte · 1 years ago
      Hi Dennis,
      By default, formulas are calculated in Excel until you are turning off the Automatic Formula Calculation. You can enable it by clicking Formulas > Calculation Options > Automatic.
  • To post as a guest, your comment is unpublished.
    Natasha · 1 years ago
    Anyone have tips on a max by color VBA?
    • To post as a guest, your comment is unpublished.
      kellytte · 1 years ago
      Hi Natasha,
      VBA is good but hard to apply. But below methods may solve your work easily too.
      Method 1: Use Find & Replace feature to select and statistic the color cells
      (1) Press Ctrl + H keys to open the Find and Replace dialog, and then enable the Find tab.
      (2) In the dialog, click Options to show advanced find options.
      (3) Then click Format > Choose Format From Cell, and select one of the specified color cells.
      (4) Click Find All. Now all cells with the same fill color are found out and listed at the bottom of the dialog.
      (5) Select one of found cells, and press Ctrl + A to select all found cells, so that these cells are selected in the worksheet.
      (6) Now you can get the count, average, sum, min, max, etc. of these cells in the task bar.
      Note: If a certain statistic result cannot be found one the taskbar, you can right click the task bar, and then tick the specified item to show it.

      Method 2: Kutools for Excel
      Kutools for Excel supports 30-day free trial. Therefore, you can download it and try its Count by color feature to solve your problem with several clicks only.
  • To post as a guest, your comment is unpublished.
    Paul · 1 years ago
    awesome fix! count by color over an entire sheet was just what i was looking for and your VBA code was tighter than others that i have looked at. Works like a charm. Thank you, and again, well done.
  • To post as a guest, your comment is unpublished.
    Mori · 2 years ago
    I copied and paste but calculation result is "0" why?? I am using Office 2016.
    • To post as a guest, your comment is unpublished.
      Krits · 1 years ago
      I try the same you this command =COUNTBYCELLCOLOR is counting only fill color but is not count by condition formating. Please help to improve code thx.
  • To post as a guest, your comment is unpublished.
    havdaddy · 2 years ago
    I've copied and pasted as stated and have used this formula for over a year but recently saved the workbook to a new name and now the function doesn't work! I can't figure out what the deal is and I'm losing hair and sleep over it! Loading the original workbook, the formula works like a charm but going back to the new one, it doesn't! I've loaded VBA and tried re-creating the function but it doesn't work. Using Office 2019 - any help appreciated.
    • To post as a guest, your comment is unpublished.
      Jku · 2 years ago
      #NAME clearly indicates some keyword is not used in 2019, say, Interior.ColorIndex. Try to figure out changing the code from minimum lines to the full by adding one by one or search for the keywords in Excel/VBA in 2019
    • To post as a guest, your comment is unpublished.
      havdaddy · 2 years ago
      I should probably have also noted that I get a #NAME? error in the cell in which I try to use the function.
  • To post as a guest, your comment is unpublished.
    Karolin · 2 years ago
    works fine, except it does not update the value in the totals when i change a cell to a diffrent colour. i have to click in the totals cell again to trigger a recount. Any Ideas how to fix this?
    • To post as a guest, your comment is unpublished.
      amirhamzah2107@gmail.com · 2 years ago
      Same here, i tried Ctrl+Alt+F9 or Ctrl+Shift+Alt+F9 to recalculate all formula and it works
  • To post as a guest, your comment is unpublished.
    Aaron · 2 years ago
    This doesn't work at all. It's total BS.
  • To post as a guest, your comment is unpublished.
    Schmingy · 2 years ago
    I was experiencing issues when attempting to use this function as-is to count/sum the lighter (pastel?) colors, at least in Excel 2016. Some debugging led me to realize that the range of "ColorIndex" values is quite limited, and the function above fails to distinguish between light yellow and light orange, reading both as ColorIndex = 19.

    Using the "Color" attribute, instead (as in "lCol = rColor.Interior.Color" and the two instances of "If rCell.Interior.Color = lCol Then", per the sample code above), resolved the issue.
  • To post as a guest, your comment is unpublished.
    Hredoy · 3 years ago
    i want to colour in excel by using if function.
  • To post as a guest, your comment is unpublished.
    Keerthi · 3 years ago
    Fix your formula, its not "=colorfunction(A,B:C,FALSE)", but "=colorfunction(A;B:C;FALSE)" its a semi-colon, not a comma.
    • To post as a guest, your comment is unpublished.
      Slegnor · 3 years ago
      I get an error when using ; but using, calculates fine?
  • To post as a guest, your comment is unpublished.
    Don Sison · 3 years ago
    This is useful for counting cells with a specific colour. How do you count all cells with any colour?
  • To post as a guest, your comment is unpublished.
    Ashwin · 3 years ago
    Its work for me but does not get Auto refreshed - evey time i have to come back to cell and press enter. Any reason ?
  • To post as a guest, your comment is unpublished.
    Bobo · 3 years ago
    I have a few merged cells in the range, and the formula calculates the count of each cell within merged cell. I need count of each merged cell as 1. Waiting for some help.
  • To post as a guest, your comment is unpublished.
    Paul · 3 years ago
    I had the #NAME Error but I realised that it was because I was spelling COLOR as Colour (UK English Spelling). It worked after I change the spelling.
  • To post as a guest, your comment is unpublished.
    Oana · 3 years ago
    I tried to use this formula in a pivot table (and in a normal excel table) where I've applied conditional formatting to color the cells and it's not working. Do you know why and how can I fix this?
    Thanks!
  • To post as a guest, your comment is unpublished.
    Will · 3 years ago
    I copied and pasted this code into the module screen but when I went back to the spreadsheet, the ColorFunction only returned the #NAME? error. What am I doing wrong? I have Microsoft Excel for Mac version 15.41.
    • To post as a guest, your comment is unpublished.
      Arjun · 3 years ago
      I used the Code and it was working fine till now. Suddenly it has stopped working. This is a very useful tool for me. Kindly help.
    • To post as a guest, your comment is unpublished.
      amohuanna · 3 years ago
      Did you check the range value and cell that contains the desired color?
    • To post as a guest, your comment is unpublished.
      kasim · 3 years ago
      Please this VBA with the name of MY FUNCTION save as add in format(type). Then you can solve that problem.
      • To post as a guest, your comment is unpublished.
        andrew.carpenter@gmail.com · 3 years ago
        I'm having this same problem, and unfortunately this answer makes absolutely zero sense in the English language. If anyone is able to suggest a translation, I'd be very interested in hearing it. Thanks.
        • To post as a guest, your comment is unpublished.
          Erin · 3 years ago
          The module & function can't have the same name. Change your module name to Color_Function instead of ColorFunction.
  • To post as a guest, your comment is unpublished.
    Jelena · 3 years ago
    Hi


    after applying range we need it jums back to VBA and says Ambiguous name detected: ColourFunction

    can you please help?
  • To post as a guest, your comment is unpublished.
    kelli.crook9@gmail.com · 3 years ago
    this doesn't work if you change the colors in the cells: so if you change yellow to red or yellow to blank, it doesn't change the count. if you add/create new colored cells then yes it updates the count, but if you change the color of a cell that has already been counted, then the count will not update.
    • To post as a guest, your comment is unpublished.
      Penny · 3 years ago
      if you go back in the cell text with the formula for summing or counting and hit enter, it will recalculate. Just have to remember to do that when changing colors on the range cells.
      • To post as a guest, your comment is unpublished.
        Tim · 3 years ago
        Is there a way to auto-calculate? going into each cell and hitting enter each time colors change is extremely tedious.
  • To post as a guest, your comment is unpublished.
    Casey · 3 years ago
    This has been so useful! Thanks very much for your help
  • To post as a guest, your comment is unpublished.
    Carolyn · 3 years ago
    The =colorfunction WAS working great for me ... got everything as I wanted it to work and then copied the sheet repeatedly ... then around the 10th copied sheet the formula stopped working ... what did I do wrong? How do I fix it?
  • To post as a guest, your comment is unpublished.
    luisa · 3 years ago
    hey, we used the colorfunction and it works fine, however as soon as we close the sheet and open it again the next day, we have to copy+paste+save it all over again, is there any way to save so it will always be there? we save the sheet in a folder that's shared within many computers. Thanks!
    • To post as a guest, your comment is unpublished.
      Tim · 3 years ago
      Luisa,
      When you open VBA, you have VBAProject (sheet1) its the place for makros for THIS SHEET. But you also have VBA Projects (PERSONAL.XLSB). Add module in PERSONAL and paste this makro there. This way you will have function avialable in every file on your computer.
      Im not sure but probably you dont have this PRESONAL.XLSB automaticly, you need to create it.
      Probably not the the fastest way but : click record macro, window will apear where you put name (whatever), shortcut (whatever) and place to store makro (chose personal macros sheet). Click ok, record any makro (puting 1 in cell A1), stop recording. Now you should have PERSONAL.XLSB in the list.
      Hope it works and helps :)
  • To post as a guest, your comment is unpublished.
    Justin · 3 years ago
    This works great unless you are trying to count colors from conditional formatting. Has anybody figured out how to solve that one?
    • To post as a guest, your comment is unpublished.
      Alex · 3 years ago
      Have you found a solution to this? I am trying to do the same thing but like you said, it does not work with conditional formatting.
  • To post as a guest, your comment is unpublished.
    cobalt.kobold@gmail.com · 3 years ago
    This doesn't differentiate between similar colours, so I changed it so it calls the HEX value of the colour instead:

    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean) As Variant
    Dim rCell As Range
    Dim lCol As Variant
    Dim vResult As Variant
    lCol = rColor.Interior.Color
    If SUM = True Then
    For Each rCell In rRange
    If rCell.Interior.Color = lCol Then
    vResult = WorksheetFunction.SUM(rCell, vResult)
    End If
    Next rCell
    Else For Each rCell In rRange
    If rCell.Interior.Color = lCol Then
    vResult = 1 + vResult
    End If
    Next rCell
    End If
    ColorFunction = vResult
    End Function

    Just remember when applying the formula that A cell of the colour you are looking for and B:C is the range to look in. Also, remember that excel can sometimes not auto-update any change to the cell so you might have to manually do it (or write a function ;-)
  • To post as a guest, your comment is unpublished.
    manali · 3 years ago
    I implemented case 1 and it worked successfully. But whenever I change the color the count does not change automatically. I need to click on Count and press enter. Can't the count be changed automatically?
    • To post as a guest, your comment is unpublished.
      Wendy · 3 years ago
      Did you find a solution to this b/c I'm having the same problem.
      • To post as a guest, your comment is unpublished.
        LiamKennedy1985 · 3 years ago
        Any news on this? I am having the same issue. Otherwise perfect :-)
        • To post as a guest, your comment is unpublished.
          Ryan · 3 years ago
          Code works perfectly but also ran into the same issue. Solved it by writing a quick macros that 'refreshes' the function(s) in the cells assigned so you have an accurate count as soon as you run the macros. Hope this helps!
          • To post as a guest, your comment is unpublished.
            Drew · 3 years ago
            Could you share the code you used to "refresh" the macros? I'd greatly appreciate it.
  • To post as a guest, your comment is unpublished.
    Hellen Hornby · 4 years ago
    Hi I tried the above in Excel and keep getting a 'ambiguous name detected' error message related to the colorfunction. Any thoughts?
  • To post as a guest, your comment is unpublished.
    a · 4 years ago
    the function does not differentiate between colours. it just counts any cell this is coloured.
    • To post as a guest, your comment is unpublished.
      cobalt.kobold@gmail.com · 3 years ago
      See my new reply, I've updated it so it will now differentiate between similar colours.
  • To post as a guest, your comment is unpublished.
    Andrea · 4 years ago
    Hi

    Fantastic tool and really easy to use so thank you!

    Is there any update on using this with conditional formatting? I think there is a fix above but I didn't understand how it worked. Simple instructions for a novice would be much appreciated!

    Thanks :)
  • To post as a guest, your comment is unpublished.
    saurabh · 4 years ago
    everything is good but what if i want to add cells across multiple worksheet
  • To post as a guest, your comment is unpublished.
    Hien · 4 years ago
    $2,322.29 2322.29
    $100.00 128.66
    $76.13 76.13
    $450.02 450.02
    $28.66 128.66
    $544.31 488.77

    0 0
    $278.66
    $636.76 636.76
    Please help the numbers on the left are the correct number but when i dragged down the formula i get the numbers on the right. As you can see some of the numbers are correct but others come out wrong. Please help me, i dont understand why this is not working. Thanks.
  • To post as a guest, your comment is unpublished.
    Hien · 4 years ago
    Please help, why do some of my numbers come out correct and some do not? Maybe two out of the 6 will be inccorect because its adding a different number from a different color.
    • To post as a guest, your comment is unpublished.
      mc · 4 years ago
      Change everything that says ".colorindex" to ".color"

      .ColorIndex only supports 256 Colours. And will round similar colours together essentuially.
  • To post as a guest, your comment is unpublished.
    RB · 4 years ago
    Very Helpful.

    Thanks a Lot.

    BR,
    RB.
  • To post as a guest, your comment is unpublished.
    Vamshi · 4 years ago
    The above function is only working for the data in a single sheet
    I want to capture the data from multiple workbooks.

    Please help .
  • To post as a guest, your comment is unpublished.
    Vamshi · 4 years ago
    Hello,

    The above function works only if the all the coloured cells are in single sheet .
    I am unable to perform the colorfunction sum if the coloured cells are in different sheets.
    Any help around this.

    EX;- Trying to consolidate the sum of coloured cells in a Master sheet it says #VALUE
  • To post as a guest, your comment is unpublished.
    Sarah Chen · 4 years ago
    Thanks for this. It's truely helpful to me!!!
  • To post as a guest, your comment is unpublished.
    Ramdzan · 4 years ago
    its a good function however it can't be save for the entire workbook, whenever to go to a new worksheet and I copy and paste the previous worksheet with the function it doesn't work and then must do it all over again, please advise if there anyway I can save the function for free ofcoz :0
  • To post as a guest, your comment is unpublished.
    AHMER IRFAN · 4 years ago
    Jazak ALLAH it was very helpful
  • To post as a guest, your comment is unpublished.
    Jacqui · 4 years ago
    Brilliant! I've been searching for a way to do this. Works perfectly and will save me so much time!!
  • To post as a guest, your comment is unpublished.
    Rod · 4 years ago
    Lack me words to express my gratitude for your code. You've saved a lot of time, wish a could buy you a beer.

    All the best, mate.
  • To post as a guest, your comment is unpublished.
    Phillip · 4 years ago
    Hi,

    Is there any way to change the code so that instead of calculating a SUM when set to TRUE, it will count the number of cells with numbers or text in?? Ideally I would like if it could count a number over 10,000, but just the COUNT function would be great. I have tried simply changing SUM in the code to COUNT, but it doesn't work.

    Any help would be great
  • To post as a guest, your comment is unpublished.
    Himmat · 4 years ago
    Good day,

    I have tried the coding provided. However I am using different color themes, which does not provide me with the answers I am seeking as the coding sums colors of a similar background and I need to obtain the sun for different colors. please assist
  • To post as a guest, your comment is unpublished.
    Ken · 4 years ago
    It's not working for me. I'm running Excel 2013 but I keep getting the Ambiguous name detected: colorfunction.
    Is there a way to fix this?
  • To post as a guest, your comment is unpublished.
    Dazzy · 4 years ago
    Fantastic! Worked very well.
  • To post as a guest, your comment is unpublished.
    Akshatha · 4 years ago
    Hi,

    Works Great. Needed a small tweak though. I have some colored empty cells which are also getting counted right now. How can i ignore those cells?

    Thanks
  • To post as a guest, your comment is unpublished.
    Sylvia · 4 years ago
    Your code works really well. Thanks. Can you now please help to alter the function of colorfunction so horizontally merged cell is counted as one? I am using the following function:
    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
    Dim rCell As Range
    Dim lCol As Long
    Dim vResult
    lCol = rColor.Interior.ColorIndex
    If SUM = True Then
    For Each rCell In rRange
    If rCell.Interior.ColorIndex = lCol Then
    vResult = WorksheetFunction.SUM(rCell, vResult)
    End If
    Next rCell
    Else
    For Each rCell In rRange
    If rCell.Interior.ColorIndex = lCol Then
    vResult = 1 + vResult
    End If
    Next rCell
    End If
    ColorFunction = vResult
    End Function

    Thanks!
  • To post as a guest, your comment is unpublished.
    GV · 4 years ago
    Works Great !!!
    Thanks for posting!!
  • To post as a guest, your comment is unpublished.
    Kailas · 4 years ago
    Thanks! very useful function :)
  • To post as a guest, your comment is unpublished.
    Ranj · 4 years ago
    I have enabled macros to count cell colors. How do add another criteria for text? Lets say I have checked a range and recieved the count for cells that are green. How do I also check how many of those had "D" as text?

    thanks!
  • To post as a guest, your comment is unpublished.
    GK · 4 years ago
    Worked like a charm when other codes would not! THANK YOU!
  • To post as a guest, your comment is unpublished.
    Saifi · 4 years ago
    Thankyou. very helpful information