메인 컨텐츠로 가기

Google 시트에서 셀 색상을 기준으로 셀을 계산하거나 합계하는 방법은 무엇입니까?

다음 스크린 샷과 같은 결과를 얻기 위해 특정 셀 배경색을 기반으로 셀 값을 계산하거나 합산합니다. 이 기사에서는 Google 시트와 Microsoft Excel 에서이 작업을 해결하는 방법에 대해 설명합니다.

Google 시트의 스크립트로 셀 색상을 기준으로 셀 값 계산

Google 시트의 스크립트를 사용하여 셀 색상을 기준으로 셀 값 합계

Microsoft Excel에서 Excel 용 Kutools를 사용하여 셀 색상의 셀 값 계산 또는 합계


Google 시트의 스크립트로 셀 색상을 기준으로 셀 값 계산

다음 스크립트는 특정 셀 색상을 기반으로 셀 값을 계산하는 데 도움이 될 수 있습니다. 다음과 같이하십시오.

1. 딸깍 하는 소리 도구 > 스크립트 편집기, 스크린 샷 참조 :

2. 열린 프로젝트 창에서 입양 부모로서의 귀하의 적합성을 결정하기 위해 미국 이민국에 > 신제품 > 스크립트 파일 코드 창을 열려면 스크린 샷을 참조하십시오.

3. 프롬프트 상자에이 스크립트 코드의 이름을 입력하십시오. 스크린 샷을 참조하십시오.

4. 딸깍 하는 소리 OK 그런 다음 다음 코드를 복사하여 붙여 넣어 원래 코드를 코드 모듈로 바꿉니다. 스크린 샷을 참조하십시오.

function countColoredCells(countRange,colorRef) {
  var activeRg = SpreadsheetApp.getActiveRange();
  var activeSht = SpreadsheetApp.getActiveSheet();
  var activeformula = activeRg.getFormula();
  var countRangeAddress = activeformula.match(/\((.*)\,/).pop().trim();
  var backGrounds = activeSht.getRange(countRangeAddress).getBackgrounds();
  var colorRefAddress = activeformula.match(/\,(.*)\)/).pop().trim();
  var BackGround = activeSht.getRange(colorRefAddress).getBackground();
  var countCells = 0;
  for (var i = 0; i < backGrounds.length; i++)
    for (var k = 0; k < backGrounds[i].length; k++)
      if ( backGrounds[i][k] == BackGround )
        countCells = countCells + 1;
  return countCells;
};

5. 그런 다음이 스크립트 코드를 저장하고 시트로 돌아가 다음 공식을 입력합니다. = countcoloredcells (A1 : E11, A1) 빈 셀에 넣은 다음 엔터 버튼 계산 된 결과를 얻으려면 키를 누르십시오. 스크린 샷보기 :

주의 사항:이 공식에서 : A1 : E11 사용하려는 데이터 범위입니다. A1 계산하려는 특정 색상으로 채워진 셀입니다.

6. 위의 공식을 반복하여 다른 특정 색상의 셀을 계산합니다.


Google 시트의 스크립트를 사용하여 셀 색상을 기준으로 셀 값 합계

특정 셀 색상으로 셀 값을 합산하려면 아래 스크립트 코드를 적용하십시오.

1. 도구 > 스크립트 편집기 프로젝트 창으로 이동하고 입양 부모로서의 귀하의 적합성을 결정하기 위해 미국 이민국에 > 신제품 > 스크립트 파일 다른 새 코드 모듈을 삽입하려면 프롬프트 상자에이 스크립트의 이름을 입력하십시오. 스크린 샷을 참조하십시오.

2. 딸깍 하는 소리 OK 열린 코드 모듈에서 스크립트 코드 아래에 복사하여 붙여 넣어 원래 코드를 바꿉니다. 스크린 샷을 참조하십시오.

function sumColoredCells(sumRange,colorRef) {
  var activeRg = SpreadsheetApp.getActiveRange();
  var activeSht = SpreadsheetApp.getActiveSheet();
  var activeformula = activeRg.getFormula();
  var countRangeAddress = activeformula.match(/\((.*)\,/).pop().trim();
  var backGrounds = activeSht.getRange(countRangeAddress).getBackgrounds();
  var sumValues = activeSht.getRange(countRangeAddress).getValues();  
  var colorRefAddress = activeformula.match(/\,(.*)\)/).pop().trim();
  var BackGround = activeSht.getRange(colorRefAddress).getBackground();
  var totalValue = 0;
  for (var i = 0; i < backGrounds.length; i++)
    for (var k = 0; k < backGrounds[i].length; k++)
      if ( backGrounds[i][k] == BackGround )
        if ((typeof sumValues[i][k]) == 'number')
          totalValue = totalValue + (sumValues[i][k]);
  return totalValue;
};

3. 그런 다음이 코드를 저장하고 시트로 돌아가 다음 공식을 입력합니다. = sumcoloredcells (A1 : E11, A1) 빈 셀에 넣고 엔터 버튼 계산 된 결과를 얻으려면 키, 스크린 샷 참조 :

주의 사항:이 공식에서 : A1 : E11 사용하려는 데이터 범위입니다. A1 합계하려는 특정 배경색이있는 셀입니다.

4. 그런 다음 위의 공식을 반복하여 다른 특정 색상의 셀을 합산 할 수 있습니다.


Microsoft Excel에서 Excel 용 Kutools를 사용하여 셀 색상의 셀 값 계산 또는 합계

Microsoft Excel에서 특정 셀 색상을 기준으로 셀 값을 계산하거나 합계하려면 Excel 용 Kutools 색상으로 계산 유틸리티를 사용하면이 작업을 최대한 빨리 완료 할 수 있습니다.

Excel 용 Kutools : 300 개 이상의 편리한 Excel 추가 기능으로 30 일 동안 제한없이 무료로 사용해 볼 수 있습니다.. 

설치 후 Excel 용 Kutools, 다음과 같이하십시오.

1. 셀 색을 기준으로 계산하거나 합할 셀 범위를 선택한 다음 쿠툴즈 플러스 > 색상으로 계산, 스크린 샷 참조 :

2. 에서 색상으로 계산 대화 상자에서 표준 서식 인사말 색상 방법 드롭 다운 목록을 선택한 다음 배경 인사말 개수 유형 드롭 다운, 스크린 샷 참조 :

3. 그런 다음 보고서 생성 버튼을 클릭하면 계산 된 결과가 포함 된 새 워크 시트가 한 번에 생성됩니다. 스크린 샷 참조 :

주의 사항:이 강력한 기능을 사용하면 조건부 서식 또는 글꼴 색상을 기반으로 셀 값을 계산할 수도 있습니다.

지금 Excel 용 Kutools 다운로드 및 무료 평가판을 클릭하십시오!

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


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

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (79)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Hey I just wanted to thank you for this guide. It totally worked! Awesome! 👍
This comment was minimized by the moderator on the site
Hii, i need help!
Did somebody have the right script?
if u have it, can u pls send me?
thanks
This comment was minimized by the moderator on the site
i need the auto update for the sumcoloredcells formula
do you know how can i have it?
This comment was minimized by the moderator on the site
questo funziona

// restituisce la somma dei valori in un range in base al colore di sfondo della cella
// uso: =SommaSeSfondo(range;cella colore di riferimento )
// =SommaSeSfondo(B1:B8;E1)

function SommaSeSfondo(sumRange,colorRef) {
var activeRg = SpreadsheetApp.getActiveRange();
var activeSht = SpreadsheetApp.getActiveSheet();
var activeformula = activeRg.getFormula();
var countRangeAddress = activeformula.match(/\((.*)\;/).pop().trim();
var backGrounds = activeSht.getRange(countRangeAddress).getBackgrounds();
var sumValues = activeSht.getRange(countRangeAddress).getValues();
var colorRefAddress = activeformula.match(/\;(.*)\)/).pop().trim();
var BackGround = activeSht.getRange(colorRefAddress).getBackground();
var totalValue = 0;
for (var i = 0; i < backGrounds.length; i++)
for (var k = 0; k < backGrounds[i].length; k++)
if ( backGrounds[i][k] == BackGround )
if ((typeof sumValues[i][k]) == 'number')
totalValue = totalValue + (sumValues[i][k]);
return totalValue;
};
This comment was minimized by the moderator on the site
Hi Samal,

You have to use the formula:

=SommeCouleurs(A:A;A1) => A:A : columns that contain the colors to count and A1 : The cell that contains the example of the color.
This comment was minimized by the moderator on the site
'm having a problem in the script for google sheets: TypeError: Cannot call method "pop" of null. (line 5, file "SumByColor"). Can you please help?
This comment was minimized by the moderator on the site
'm having a problem in the script for google sheets: TypeError: Cannot call method "pop" of null. (line 5, file "SumByColor"). Can you please help?
This comment was minimized by the moderator on the site
'm having a problem in the script for google sheets: TypeError: Cannot call method "pop" of null. (line 5, file "SumByColor"). Can you please help?
This comment was minimized by the moderator on the site
Bonjour a tous,

J'utilise Google Sheet en version Française et voici le script le plus fonctionnel que j'ai trouvé:

function SommeCouleurs(plage,couleur) {
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var formule = activeRange.getFormula();


var laplage = formule.match(/\((.*)\;/).pop();
var range = activeSheet.getRange(laplage);
var bg = range.getBackgrounds();
var values = range.getValues();

var lacouleur = formule.match(/\;(.*)\)/).pop();
var colorCell = activeSheet.getRange(lacouleur);
var color = colorCell.getBackground();

var total = 0;

for(var i=0;i<bg.length;i++)
for(var j=0;j<bg[0].length;j++)
if( bg[i][j] == color )
total=total+(values[i][j]*1);
return total;

};


function CompteCouleurs(plage,couleur) {
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var formule = activeRange.getFormula();


var laplage = formule.match(/\((.*)\;/).pop();
var range = activeSheet.getRange(laplage);
var bg = range.getBackgrounds();
var values = range.getValues();

var lacouleur = formule.match(/\;(.*)\)/).pop();
var colorCell = activeSheet.getRange(lacouleur);
var color = colorCell.getBackground();

var count = 0;


for(var i=0;i<bg.length;i++)
for(var j=0;j<bg[0].length;j++)
if( bg[i][j] == color )
count=count+1;
return count;
};

Formule a utiliser:

=CompteCouleurs(A2:A;A1)

Il s'actualise automatiquement.
En espérant que ca vous aidera
This comment was minimized by the moderator on the site
Добрый день!
Проверил, автоматически не пересчитывает, если изменить цвет в диапазоне ((
This comment was minimized by the moderator on the site
非常感謝大大分享~很實用我是用Google 試算表編輯
請問程式碼能教怎麼加總指定的文字顏色的數字總和嗎? (把 儲存格顏色 改為 文字顏色) 拜託~~
This comment was minimized by the moderator on the site
Hi, I have set it in google sheets as You have described, but it showed me error "Type error: Cannot read property 'pop' of null". PLS can you help me?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations