Excel Tips: Count/sum cells by color (background, font, conditional formatting)
일상적인 작업에서 색상 표시는 중요한 데이터를 빠르게 구분하고 강조하는 인기 있는 방법입니다. 하지만 특정 색상(채우기 색상, 글꼴 색상, 조건부 서식)에 따라 셀 데이터를 계산하거나 합산하려면 어떻게 해야 할까요? 기본적으로 Excel은 색상별로 계산하거나 합산하는 직접적인 기능을 제공하지 않습니다. 그럼에도 불구하고 몇 가지 트릭과 간접적인 방법을 사용하면 이를 해결할 수 있습니다. 이 문서에서는 색상별로 데이터를 계산하거나 합산하는 방법을 살펴보겠습니다.
배경색에 따라 셀 계산 및 합산하기
예를 들어, 아래 스크린샷과 같이 다양한 배경색으로 채워진 데이터 범위가 있다고 가정해 보겠습니다. 특정 색상에 따라 셀을 계산하거나 합산하려고 하는 경우, Excel은 배경색에 따라 셀을 계산하거나 합산하는 직접적인 기능을 제공하지 않습니다. 그러나 약간의 창의성과 유용한 기술을 활용하면 이 작업을 수행할 수 있습니다. 이번 섹션에서는 몇 가지 유용한 방법을 살펴보겠습니다.
사용자 정의 함수를 사용하여 배경색에 따라 셀 계산 및 합산하기
여기서는 Excel에서 이 작업을 해결하기 위해 사용자 정의 함수를 생성하고 사용하는 방법을 보여드리겠습니다. 다음 단계를 따르세요:
1단계: VBA 모듈 편집기를 열고 코드 복사하기
- Alt + F11 키를 눌러 Microsoft Visual Basic for Applications 창을 엽니다.
- 열린 창에서 Insert > Module을 클릭하여 새 빈 모듈을 생성합니다.
- 그런 다음 아래 코드를 빈 모듈에 복사하여 붙여넣습니다.
VBA 코드: 배경색에 따라 셀 계산 및 합산하기Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean = False) As Variant 'Updateby Extendoffice Dim rCell As Range Dim lCol As Long Dim vResult As Double lCol = rColor.Interior.ColorIndex vResult = 0 If SUM Then For Each rCell In rRange If rCell.Interior.ColorIndex = lCol Then vResult = vResult + rCell.Value End If Next rCell Else For Each rCell In rRange If rCell.Interior.ColorIndex = lCol Then vResult = vResult + 1 End If Next rCell End If ColorFunction = vResult End Function
2단계: 배경색에 따라 셀을 계산 및 합산하기 위한 공식 생성하기
위의 코드를 붙여넣은 후 모듈 창을 닫고 다음 공식을 적용하세요:
- 특정 배경색에 따라 셀 계산하기:
아래 제공된 공식을 원하는 결과 셀에 복사하거나 입력하세요. 그런 다음 채우기 핸들을 아래로 드래그하여 다른 결과를 얻으세요. 스크린샷 참조:
=colorfunction(G2,$B$2:$E$12,FALSE)
참고: 이 공식에서 G2는 일치시키려는 특정 배경색이 있는 참조 셀입니다; $B$2:$E$12는 G2의 색상과 일치하는 셀의 개수를 계산하려는 범위입니다; FALSE는 일치하는 색상을 가진 셀을 계산하는 데 사용됩니다. - 특정 배경색에 따라 셀 합산하기:
아래 제공된 공식을 원하는 결과 셀에 복사하거나 입력하세요. 그런 다음 채우기 핸들을 아래로 드래그하여 다른 결과를 얻으세요. 스크린샷 참조:
=colorfunction(G2,$B$2:$E$12,TRUE)
참고: 이 공식에서 G2는 일치시키려는 특정 배경색이 있는 참조 셀입니다; $B$2:$E$12는 G2의 색상과 일치하는 셀의 개수를 계산하려는 범위입니다; TRUE는 일치하는 색상을 가진 셀을 합산하는 데 사용됩니다.
강력한 기능을 사용하여 배경색에 따라 셀 계산 및 합산하기
프로그래밍에 익숙하지 않은 분들에게 VBA는 상당히 복잡하게 느껴질 수 있습니다. 여기서는 강력한 도구인 Kutools for Excel을 소개하겠습니다. Count by Color 기능을 통해 몇 번의 클릭만으로 배경색에 따라 쉽게 계산(개수, 합계, 평균 등)할 수 있습니다. 인상적으로도 Count by Color 기능은 배경색에 그치지 않고 글꼴 색상과 조건부 서식까지 구분하고 계산할 수 있습니다.
Kutools for Excel을 다운로드하고 설치한 후, 먼저 특정 배경색에 따라 계산하거나 합산하려는 데이터 범위를 선택하세요. 그런 다음 Kutools Plus로 이동하여 Count by Color를 선택하세요.
Count by Color 대화 상자에서 다음 작업을 지정하세요:
- Color method 드롭다운 목록에서 Standard formatting을 선택하세요;
- Count type 드롭다운 목록에서 Background를 지정하고, 대화 상자에서 각 배경색에 대한 통계 결과를 미리볼 수 있습니다;
- 마지막으로 Generate report를 클릭하여 계산된 결과를 새로운 워크북으로 내보냅니다.
결과:
이제 통계가 포함된 새로운 워크북을 받게 됩니다. 스크린샷 참조:
- The Count by Color 기능은 또한 표준 글꼴 색상, 조건부 서식에서의 배경 또는 글꼴 색상, 그리고 채우기와 조건부 서식 색상의 조합에 따른 셀 계산 및 합산을 지원합니다.
- 이 기능에 관심이 있다면 30일 무료 체험판을 다운로드하려면 여기를 클릭하세요.
Filter 및 SUBTOTAL 기능을 사용하여 배경색에 따라 셀 계산 및 합산하기
아래 스크린샷과 같은 과일 판매 테이블이 있다고 가정해 보겠습니다. 우리는 Amount 열의 색상이 있는 셀을 계산하거나 합산할 것입니다. Amount 열.
1단계: SUBTOTAL 함수 적용하기
SUBTOTAL 함수를 입력하기 위해 빈 셀을 선택하세요.
- 같은 배경색을 가진 모든 셀을 계산하려면 다음 공식을 입력하세요:
=SUBTOTAL(102, F2:F16)
- 같은 배경색을 가진 모든 셀을 합산하려면 다음 공식을 입력하세요:
=SUBTOTAL(109, F2:F16)
- 참고: 위의 공식에서 102는 숨겨진 셀을 제외한 필터링된 목록에서 숫자 값을 계산하는 것을 나타내며; 109는 숨겨진 셀을 제외한 필터링된 목록에서 값을 합산하는 것을 나타냅니다; F2:F16은 계산될 카운트 또는 합계의 범위입니다.
2단계: 특정 색상에 따라 셀 필터링하기
- 테이블의 헤더를 선택하고 Data > Filter를 클릭하세요. 스크린샷 참조:
- Click the Filter icon
in the header cell of the Amount column, and click Filter by Color and the specified color you will count by successively. See screenshot:
Result:
After filtering, the SUBTOTAL formulas automatically count and sum the colored cells in the Amount column. See screenshot:
Count and sum cells based on font color
Want to count or sum cells based on their font color in Excel? Let's say you have the data, like in the given screenshot, with cells containing texts in red, blue, orange and black color. Excel doesn't make this easy by default. But don't worry! In this section, we'll show you some simple tricks to do just that.
Count and sum cells based on font color with User Defined Function
To count and sum cells with specific font colors, the following User Defined Function may help you to solve this task. Please do with the following steps:
Step 1: Open the VBA module editor and copy the code
- Press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
- In the opened window, click Insert > Module to create a new blank module.
- Then, copy and paste the below code into the blank module.
VBA code: Count and sum cells based on font colorFunction ProcessByFontColor(pRange1 As Range, pRange2 As Range, FunctionType As String) As Double 'Updateby Extendoffice Application.Volatile Dim rng As Range Dim xTotal As Double Dim xCount As Double xTotal = 0 xCount = 0 For Each rng In pRange1 If rng.Font.Color = pRange2.Font.Color Then If UCase(FunctionType) = "SUM" Then xTotal = xTotal + rng.Value ElseIf UCase(FunctionType) = "COUNT" Then xCount = xCount + 1 End If End If Next If UCase(FunctionType) = "SUM" Then ProcessByFontColor = xTotal ElseIf UCase(FunctionType) = "COUNT" Then ProcessByFontColor = xCount Else ProcessByFontColor = CVErr(xlErrValue) End If End Function
Step 2: Create formulas to count and sum cells by font color
After pasting the above code, close the module window, then apply the following formulas:
- Count cells based on the specific font color:
Copy or type the formula provided below into your desired cell for the result. Then, drag the fill handle downwards to get other results. See screenshot:
=ProcessByFontColor($B$2:$E$12,G2, "COUNT")
Note: In this formula, G2 is the reference cell with the specific font color you want to match; $B$2:$E$12 is the range where you want to count the number of cells of G2's color. - Sum cells based on the specific font color:
Copy or type the formula provided below into your desired cell for the result. Then, drag the fill handle downwards to get other results. See screenshot:
=ProcessByFontColor($B$2:$E$12,G2, "SUM")
Note: In this formula, G2 is the reference cell with the specific font color you want to match; $B$2:$E$12 is the range where you want to count the number of cells of G2's color.
Count and sum cells based on font color with an easy feature
Looking to effortlessly count or sum cell values in Excel based on font color? Dive into Kutools for Excel's Count by Color feature! With this smart tool, counting and summing cells by specific font color becomes a breeze. Discover how Kutools can transform your Excel experience.
After downloading and installing Kutools for Excel, first, select the data range that you want to count or sum cells based on a specific font color. Then, click Kutools Plus > Count by Color to open the Count by Color dialog box.
In the Count by Color dialog box, please specify the operations:
- Select Standard formatting from the Color method drop down list;
- Specify Font from the Count type drop down list, and you can preview the statistical results for each font color in the dialogue box;
- At last, click Generate report to export the calculated results to a new workbook.
Result:
Now, you have a new workbook displaying the detailed statistics based on font color. See screenshot:
Count and sum cells based on conditional formatting color
In Excel, you may commonly use the Conditional Formatting to apply specific color to cells that meet certain criteria, making data visualization intuitive. But what if you need to count or sum those specially formatted cells? While Excel doesn't offer a direct way for this, here are ways to maneuver around this limitation.
Count and sum conditionally formatted cells with VBA code
Counting and summing conditionally formatted cells in Excel is not straightforward using built-in functions. However, you can accomplish this task using VBA code. Let's go over how you can use VBA for this:
Step 1: Open the VBA module editor and copy the code
- Press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
- In the opened window, click Insert > Module to create a new blank module.
- Then, copy and paste the below code into the blank module.
VBA code: Count and sum cells based on conditional formatting colorSub SumCountByConditionalFormat() 'Updateby Extendoffice Dim sampleColor As Range Dim selectedRange As Range Dim cell As Range Dim countByColor As Long Dim sumByColor As Double Dim refColor As Long Set selectedRange = Application.InputBox("Select a range to evaluate:", _ "Kutools for Excel", _ Type:=8) If selectedRange Is Nothing Then Exit Sub Set sampleColor = Application.InputBox("Select a conditional formatting color:", _ "Kutools for Excel", _ Type:=8) If Not sampleColor Is Nothing Then refColor = sampleColor.Cells(1, 1).DisplayFormat.Interior.color For Each cell In selectedRange If cell.DisplayFormat.Interior.color = refColor Then countByColor = countByColor + 1 sumByColor = sumByColor + cell.Value End If Next cell MsgBox "Count: " & countByColor & vbCrLf & _ "Sum: " & sumByColor, _ vbInformation, "Results based on Conditional Format Color" End If End Sub
Step 2: Execute this VBA code
- After pasting the code, press F5 key to run this code, a prompt box will appear, please select the data range where you want to count and sum cells based on conditional formatting. Then, click OK, See screenshot:
- In another prompt box, select a specific conditional formatting color that you want to count and sum, and click OK button, see screenshot:
Result:
Now, the result, which includes both the count and sum of cells with the specified conditional formatting color, will be displayed in the popped-out box. See screenshot:
Count and sum conditionally formatted cells with a smart feature
If you're looking for other quick and easy methods to count and sum conditionally formatted cells, Kutools for Excel is your go-to solution. Its Count by Color feature can solve this task in just a few clicks. Dive in to discover the efficiency and precision Kutools can bring to your workflow.
After downloading and installing Kutools for Excel, first, select the data range that you want to count or sum cells based on a specific conditional formatting color. Then, click Kutools Plus > Count by Color to open the Count by Color dialog box.
In the Count by Color dialog box, please specify the operations:
- Select Conditional formatting from the Color method drop down list;
- Specify Background from the Count type drop down list, and you can preview the statistical results for each conditionla formatting color in the dialogue box;
- At last, click Generate report to export the calculated results to a new workbook.
Result:
Now, you have a new workbook displaying the detailed statistics based on the conditional formatting color. See screenshot:
Related Articles:
- If the font color is red then return a specific text
- How could you return a specific text if the font color is red in another cell as below screenshot shown? In this article, I will introduce some tricks for doing some operations based on the red font text in Excel.
- Filter data by multiple colors
- Normally, in Excel, you can quickly filter rows with only one color, but, have you ever considered filtering rows with multiple colors at the same time? This article, I will talk about quick trick for you to deal with this problem.
- Add color to drop down list
- In Excel, create a drop-down list can help you a lot, and sometimes, you need to color coded the drop down list values depending on the corresponding selected. For instance, I have created a drop-down list of the fruit names, when I select Apple, I need the cell is colored with red automatically, and when I choose Orange, the cell can be colored with orange.
- Color alternate rows for merged cells
- It is very helpful to format alternate rows with a different color in a large data for us to scan the data, but, sometimes, there may be some merged cells in your data. To highlight the rows alternately with a different color for the merged cells as below screenshot shown, how could you solve this problem in Excel?
최고의 오피스 생산성 도구
🤖 | Kutools AI Aide: 지능형 실행을 기반으로 데이터 분석 혁신 지능형 실행 | 코드 생성 | 사용자 정의 수식 생성 | 데이터 분석 및 차트 생성 | Kutools Functions 호출… |
인기 기능: 중복 찾기, 강조 또는 중복 표시 | 빈 행 삭제 | 데이터 손실 없이 열 또는 셀 병합 | 반올림... | |
슈퍼 LOOKUP: 다중 조건 VLookup | 다중 값 VLookup | 다중 시트 조회 | 퍼지 매치 .... | |
고급 드롭다운 목록: 드롭다운 목록 신속 생성 | 의존형 드롭다운 목록 | 다중 선택 드롭다운 목록.... | |
열 매니저: 지정 개수 열 추가 | 열 이동 | 숨겨진 열 표시 상태 전환 | 범위 및 열 비교 ... | |
주요 기능: 그리드 포커스 | 디자인 보기 | 향상된 수식 표시줄 | 통합 문서 & 시트 관리 | 자동 텍스트 라이브러리 | 날짜 선택기 | 데이터 병합 | 셀 암호화/해독 | 목록별 이메일 보내기 | 슈퍼 필터 | 특수 필터 (굵게/이탤릭/취소선 필터...)... | |
Top15 도구 세트: 12개 텍스트 도구(텍스트 추가, 특정 문자 삭제, ...) | 50+ 차트 유형(간트 차트, ...) | 40+ 실용 수식(생일을 기반으로 나이 계산, ...) | 19개 삽입 도구(QR 코드 삽입, 경로에서 그림 삽입, ...) | 12개 변환 도구(단어로 변환하기, 통화 변환, ...) | 7개 병합 & 분할 도구(고급 행 병합, 셀 분할, ...) | ... 그리고 그 외 |
Kutools for Excel로 Excel 실력을 한 단계 업그레이드하고, 그 어떤 때보다 뛰어난 효율성을 경험하세요. Kutools for Excel은300개 이상의 고급 기능을 제공하여 생산성을 높이고 저장 시간을 줄여줍니다. 가장 필요한 기능을 지금 바로 확인하세요...
Office Tab이 오피스에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다
- Word, Excel, PowerPoint에서 탭 기반 편집과 읽기를 활성화합니다.
- 여러 문서를 새 창이 아닌 동일한 창의 새 탭에서 열고 생성하세요.
- 생산성이50% 향상되며, 매일 수백 번의 마우스 클릭을 줄일 수 있습니다!
Table of contents
- Video
- Count and sum cells based on background color
- By using User Defined Function
- By using a powerful feature – Kutools for Excel
- By using Filter and SUBTOTAL
- Count and sum cells based on font color
- By using User Defined Function
- By using an easy feature – Kutools for Excel
- Count and sum cells based on conditional formatting color
- By using VBA code
- By using a smart feature – Kutools for Excel
- Related Articles
- The Best Office Productivity Tools
- Comments