Note: The other languages of the website are Google-translated. Back to English
Logáil isteach  \/ 
x
or
x
Cláraigh  \/ 
x

or

Conas cealla a chomhaireamh agus a shuimiú bunaithe ar dhath cúlra in Excel?

Má cheaptar go bhfuil raon cealla agat a bhfuil dathanna cúlra difriúla orthu, mar shampla dearg, glas, gorm agus mar sin de, ach anois ní mór duit a áireamh cé mhéad cealla sa raon sin a bhfuil dath cúlra áirithe orthu agus suim a thabhairt do na cealla daite leis an dath áirithe céanna . In Excel, níl aon fhoirmle dhíreach ann chun Suim agus Líon na gcealla dathanna a ríomh, anseo tabharfaidh mé roinnt bealaí duit chun an fhadhb seo a réiteach.


Cealla daite Líon agus Suim de réir Scagaire agus SUBTOTAL

Má cheaptar go bhfuil tábla díolachán torthaí againn mar a thaispeántar thíos an pictiúr, agus déanfaimid na cealla daite sa cholún Méid a chomhaireamh nó a shuimiú. Sa chás seo, is féidir linn an colún Méid a scagadh de réir datha, agus ansin cealla daite scagtha a chomhaireamh nó a shuimiú de réir na feidhme SUBTOTAL go héasca in Excel.

1. Roghnaigh cealla bána chun an fheidhm SUBTOTAL a iontráil.

  1. Chun gach cealla a bhfuil an dath cúlra céanna orthu a chomhaireamh, cuir isteach an fhoirmle le do thoil = SUBTOTAL (102, E2: E20);
  2. Chun suim a thabhairt do gach cealla leis an dath cúlra céanna, cuir isteach an fhoirmle le do thoil = SUBTOTAL (109, E2: E20);


nótaí: Sa dá fhoirmle, is é E2: E20 an colún Méid ina bhfuil na cealla daite, agus is féidir leat iad a athrú de réir mar is gá duit.

2. Roghnaigh ceanntásc an tábla, agus cliceáil Dáta > scagairí. Féach an pictiúr:

3. Cliceáil ar an deilbhín Scagaire  i gcill ceanntásc an cholúin Méid, agus cliceáil Scag de réir Dath agus an dath sonraithe a chomhaireamhfaidh tú de réir a chéile. Féach an pictiúr:

Tar éis iad a scagadh, déanann an dá fhoirmle SUBTOTAL gach cealla daite scagtha sa cholún Méid a chomhaireamh agus a achoimriú go huathoibríoch. Féach an pictiúr:

nótaí: Éilíonn an modh seo go bhfuil na cealla daite a chomhaireamh tú nó a suimfidh tú sa cholún céanna.

Cliceáil amháin chun comhaireamh, suim agus meánchealla daite in Excel

Leis an scoth Líon de réir Dath gné de Kutools le haghaidh Excel, is féidir leat cealla a chomhaireamh, suim agus meán a dhéanamh go tapa trí dhath líonta sonraithe nó dath cló gan ach cliceáil amháin in Excel. Ina theannta sin, gheobhaidh an ghné seo amach luachanna max agus min na gcealla de réir an dath líonta nó an dath cló. Triail Saor in Aisce Gné Iomlán 30 lá!
comhaireamh ad de réir datha 2

Kutools le haghaidh Excel - Cuimsíonn sé níos mó ná 300 uirlis áisiúil le haghaidh Excel. Triail saor in aisce gné iomlán 30 lá, níl aon chárta creidmheasa ag teastáil! Get sé anois

Cealla daite Líon nó Suim de réir feidhme GET.CELL

Sa mhodh seo, cruthóimid raon ainmnithe leis an bhfeidhm GET.CELL, gheobhaidh muid cód datha na gcealla, agus ansin déanfaimid an cód datha a chomhaireamh nó a shuimiú go héasca in Excel. Déan mar a leanas le do thoil:

1. Cliceáil Foirmlí > Sainmhínigh Ainm. Féach an pictiúr:

2. Sa dialóg Ainm Nua, déan mar atá thíos an pictiúr a thaispeántar:
(1) Clóscríobh ainm sa bhosca Ainm;
(2) Iontráil an fhoirmle = GET.CELL (38, Bileog4! $ E2) sa bhosca Tagraíonn sé do bhosca (faoi ​​deara: san fhoirmle, 38 ciallaíonn sé an cód cille a thabhairt ar ais, agus Bileog4! $ E2 Is í an chéad chill sa cholún Méid ach ceanntásc an cholúin a chaithfidh tú a athrú bunaithe ar do shonraí tábla.)
(3) Cliceáil ar an OK cnaipe.

3. Anois cuir colún Datha nua ar dheis ar an tábla bunaidh. Ansin clóscríobh an fhoirmle = NumColor , agus tarraing an láimhseáil AutoFill chun an fhoirmle a chur i bhfeidhm ar chealla eile sa cholún Datha. Féach an pictiúr:
nótaí: San fhoirmle, NumColor an raon ainmnithe a shonraíomar sa chéad 2 chéim. Ní mór duit é a athrú go dtí an t-ainm sonraithe a shocraigh tú.

Anois filleann cód datha gach cille sa cholún Méid sa Cholún Datha. Féach an pictiúr:

4. Cóipeáil agus liostáil an dath líonta i raon bán sa bhileog oibre ghníomhach, agus clóscríobh na foirmlí in aice leis mar atá thíos an pictiúr a thaispeántar:
A. Chun cealla a chomhaireamh de réir datha, cuir isteach an fhoirmle le do thoil = COUNTIF ($ F $ 2: $ F $ 20, NumColor);
B. Chun cealla a shuimiú de réir datha, cuir isteach an fhoirmle le do thoil = SUMIF ($ F $ 2: $ F $ 20, NumColor, $ E $ 2: $ E $ 20).

nótaí: Sa dá fhoirmle, $ F $ 2: $ F $ 20 Is é an colún Dath, NumColor is é an raon ainmnithe sonraithe, $ E $ 2: $ E $ 20 Is é an Colún Méid é, agus is féidir leat iad a athrú de réir mar is gá duit.

Anois feicfidh tú go ndéantar na cealla sa cholún Méid a chomhaireamh agus a suimiú de réir a ndathanna líonta.


Déan cealla a chomhaireamh agus a shuimiú bunaithe ar dhath líonta ar leith le Feidhm Shainithe ag an Úsáideoir

Má scaiptear na cealla daite i raon mar atá faoi bhun an scáileáin a thaispeántar, ní féidir leis an dá mhodh thuas na cealla daite a chomhaireamh ná a shuimiú. Anseo, tabharfaidh an modh seo VBA isteach chun an fhadhb a réiteach.

1. Coinnigh síos an ALT + F11 eochracha, agus osclaíonn sé an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Cliceáil Ionsáigh > Modúil, agus greamaigh an cód seo a leanas i bhFuinneog an Mhodúil.

VBA: Cealla a chomhaireamh agus a shuimiú bunaithe ar dhath an chúlra:

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. Ansin sábháil an cód, agus cuir an fhoirmle seo a leanas i bhfeidhm:
A. Líon na cealla daite: = dathfheidhmiú (A, B: C, BRÉAGACH)
B. Suimigh na cealla daite: = dathfheidhmiú (A, B: C, TRUE)

Nóta: Sna foirmlí thuas, A an cill leis an dath cúlra ar leith is mian leat an comhaireamh agus an tsuim a ríomh, agus B: C. an raon cille inar mian leat an comhaireamh agus an tsuim a ríomh.

4. Tóg an seat seo a leanas mar shampla, iontráil an fhoirmle= dathfheidhmiú (A1, A1: D11, BRÉAGACH) chun na cealla buí a chomhaireamh. Agus bain úsáid as an bhfoirmle = dathfheidhmiú (A1, A1: D11, TRUE) chun na cealla buí a shuimiú. Féach an pictiúr:

5. Más mian leat cealla daite eile a chomhaireamh agus a shuimiú, déan céim 4. Déan na torthaí seo a leanas le do thoil: Ansin


Cealla Líon agus Suim bunaithe ar dhath líonta ar leith le Feidhmeanna Kutools

Tacaíonn Kutools for Excel le roinnt feidhmeanna úsáideacha freisin chun cabhrú le húsáideoirí Excel ríomhanna speisialta a dhéanamh, a deir comhaireamh de réir dath cúlra cille, suim de réir clómhéid, srl.

Kutools le haghaidh Excel - Cuimsíonn sé níos mó ná 300 uirlis áisiúil le haghaidh Excel. Triail saor in aisce gné iomlán 30 lá, níl aon chárta creidmheasa ag teastáil! Triail In Aisce Anois!

1. Roghnaigh an chill bhán ina gcuireann tú na torthaí comhairimh, agus cliceáil Kutools > Feidhmeanna Kutools > Staidrimh & Mata > COUNTBYCELLCOLOR. Féach an pictiúr:

2. Sa dialóg Argóintí Feidhm, sonraigh le do thoil an raon ina mbeidh tú ag comhaireamh cealla daite sa Tagairt bosca, roghnaigh an chill atá líonta ag an dath cúlra sonraithe sa Dath_index_nr bosca, agus cliceáil ar an OK cnaipe. Féach an pictiúr:

Nótaí:
(1) Is féidir leat an Fheidhm shonraithe Kutools a chlóscríobh freisin = COUNTBYCELLCOLOR ($ A $ 1: $ E $ 20, G2)  sa chill bán nó sa bharra foirmle go díreach chun na torthaí comhairimh a fháil;
(2) Cliceáil Kutools > Feidhmeanna Kutools > Staidrimh & Mata > SUMBYCELLCOLOR nó cineál = SUMBYCELLCOLOR ($ A $ 1: $ E $ 20, G2) sa chill bhán go díreach chun cealla a shuimiú bunaithe ar an dath cúlra sonraithe.
Iarratas a dhéanamh ar an COUNTBYCELLCOLOR agus SUMBYCELLCOLOR feidhmeanna do gach dath cúlra ar leithligh, agus gheobhaidh tú na torthaí mar atá thíos ar an scáileán:

Feidhmeanna Kutools tá roinnt feidhmeanna ionsuite ann chun cabhrú le húsáideoirí Excel ríomh go héasca, lena n-áirítear Líon / Suim / Meánchealla Infheicthe, Líon / Suim de réir dath na cille, Líon / Suim de réir dath cló, Comhairigh carachtair, Líon de réir cló trom, Etc. Bíodh Triail In Aisce agat!


Cealla Líon agus Suim bunaithe ar dhath líonta ar leith le Kutools for Excel

Leis an bhFeidhm Sainmhínithe Úsáideora thuas, ní mór duit an fhoirmle a iontráil ceann ar cheann, má tá go leor dathanna éagsúla ann, beidh an modh seo tedious agus Tógann am. Ach má tá Kutools le haghaidh Excel'S Líon de réir Dath fóntais, is féidir leat tuairisc ar na cealla daite a ghiniúint go tapa. Ní amháin gur féidir leat na cealla daite a chomhaireamh agus a shuimiú, ach is féidir leat meánluachanna, uasluachanna agus luachanna an raon daite a fháil freisin.

Kutools le haghaidh Excel - Cuimsíonn sé níos mó ná 300 uirlis áisiúil le haghaidh Excel. Triail saor in aisce gné iomlán 30 lá, níl aon chárta creidmheasa ag teastáil! Triail In Aisce Anois!

1. Roghnaigh an raon is mian leat a úsáid, agus cliceáil Kutools Plus > Líon de réir Dath, féach ar an scáileán:

2. Agus sa Líon de réir Dath bosca dialóige, déan mar a thaispeántar thíos an scáileán:
(1) Roghnaigh Formáidiú caighdeánach ó na Modh datha liosta anuas;
(2) Roghnaigh cúlra ó na Cineál comhaireamh liosta anuas.
(3) Cliceáil an cnaipe Tuairiscigh Gin.

nótaí: Chun cealla daite a chomhaireamh agus a shuimiú de réir dath formáidithe coinníollach ar leith, roghnaigh le do thoil Formáidiú coinníollach ó na Modh datha liosta anuas sa dialóg thuas, nó roghnaigh Formáidiú caighdeánach agus coinníollach ón liosta anuas chun na cealla go léir a líonann an dath sonraithe a chomhaireamh.

Anois gheobhaidh tú leabhar oibre nua leis na staitisticí. Féach an pictiúr:

An Líon de réir Dath ríomhann gné (Líon, Suim, Meán, Uasmhéid, srl.) cealla de réir dath cúlra nó dath cló. Bíodh Triail In Aisce agat!


Airteagal gaolmhar:


Taispeántas: Líon agus suim na gcealla bunaithe ar chúlra, dath formáidithe coinníollach:


Kutools le haghaidh Excel Cuimsíonn sé níos mó ná 300 uirlis áisiúil le haghaidh Excel, saor in aisce le triail gan teorainn i 30 lá. Íoslódáil agus Triail In Aisce Anois!

Na hUirlisí Táirgiúlachta Oifige is Fearr

Réitíonn Kutools for Excel an chuid is mó de do chuid Fadhbanna, agus Méadaíonn sé do Tháirgiúlacht 80%

  • Athúsáid: Cuir isteach go tapa foirmlí casta, cairteacha agus aon rud a d'úsáid tú roimhe seo; Cealla a Chriptiú le pasfhocal; Cruthaigh Liosta Ríomhphoist agus seol ríomhphoist ...
  • Barra Foirmle Super (cuir línte iolracha téacs agus foirmle in eagar go héasca); Leagan Amach Léitheoireachta (líon mór cealla a léamh agus a chur in eagar go héasca); Greamaigh go dtí an Raon Scagtha...
  • Cumaisc Cealla / Sraitheanna / Colúin gan Sonraí a chailleadh; Ábhar Cealla Scoilt; Comhcheangail Sraitheanna / Colúin Dúblacha... Cill Dúblach a Chosc; Déan comparáid idir Ranganna...
  • Roghnaigh Dúblach nó Uathúil Sraitheanna; Roghnaigh Blank Rows (tá na cealla uile folamh); Aimsigh Super agus Fuzzy Aimsigh i go leor Leabhar Oibre; Roghnaigh go randamach ...
  • Cóip Díreach Cealla Il gan tagairt fhoirmle a athrú; Tagairtí Cruthaigh Auto chuig Bileoga Il; Cuir Urchair isteach, Boscaí Seiceála agus go leor eile ...
  • Sliocht Téacs, Cuir Téacs leis, Bain de réir Poist, Bain Spás; Subtotals Paging a chruthú agus a phriontáil; Tiontaigh Idir Ábhar Cealla agus Tráchtanna...
  • Scagaire Super (scéimeanna scagaire a shábháil agus a chur i bhfeidhm ar bhileoga eile); Ard-Sórtáil de réir míosa / seachtaine / lae, minicíocht agus níos mó; Scagaire Speisialta le cló trom, iodálach ...
  • Comhcheangail Leabhair Oibre agus Bileoga Oibre; Cumaisc Táblaí bunaithe ar eochaircholúin; Roinn Sonraí i Ilbhileoga; Baisc Tiontaigh xls, xlsx agus PDF...
  • Níos mó ná 300 gné chumhachtach. Tacaíochtaí Office / Excel 2007-2019 agus 365. Tacaíonn sé le gach teanga. Imscaradh éasca i d’fhiontar nó d’eagraíocht. Gnéithe iomlána triail saor in aisce 30 lá. Ráthaíocht ar ais airgid 60 lá.
cluaisín kte 201905

Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
bun 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 · 9 months 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 · 8 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 · 9 months 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 · 9 months 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 · 11 months 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 · 2 years ago
    i want to colour in excel by using if function.
  • To post as a guest, your comment is unpublished.
    Keerthi · 2 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 · 2 years ago
      I get an error when using ; but using, calculates fine?
  • To post as a guest, your comment is unpublished.
    Don Sison · 2 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 · 3 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 · 3 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 · 3 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 · 3 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 · 3 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 · 3 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 · 3 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