SOLVED

Counting color Filled Cells across entire workbook?

%3CLINGO-SUB%20id%3D%22lingo-sub-1924385%22%20slang%3D%22en-US%22%3ECounting%20color%20Filled%20Cells%20across%20entire%20workbook%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1924385%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20working%20on%20a%20project%20to%20help%20stream%20line%20and%20improve%20my%20works%20Material%20Process%20Sheets.%20I%20have%20made%20a%20few%20Macros%20and%20have%20some%20conditional%20formatting%20in%20the%20Workbook.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Workbook%20contains%20Locked%20and%20unlocked%20cells%20and%20sheets.%20Part%20of%20the%20daily%20process%20is%20to%20check%20in%20and%20track%20were%20the%20material%20is%20in%20the%20process%2C%20weather%20it%20is%20on%20order%20or%20in%20the%20machine%20shop%2C%20or%20even%20out%20for%20treatment.%20We%20do%20this%20by%20%22highlighting%22%20the%20cell%20with%20the%20fill%20feature.%20I%20would%20like%20to%20count%20the%20last%20cell%20in%20each%20row%20when%20it%20has%20been%20%22Highlighted%22%2C%20meaning%20all%20processes%20are%20done%20at%20the%20material%20is%20ready%20to%20be%20assembled.%20The%20Workbook%20can%20have%20from%20one%20to%20multiple%20pages.%20So%20here%20is%20my%20question%2C%20is%20there%20a%20way%20to%20count%20the%20filled%20cells%20across%20the%20Workbook%2C%20but%20limit%20to%20a%20specific%20set%20of%20cells%20on%20each%20Sheet%20and%20limit%20to%20only%20look%20at%20certain%20sheets%20or%20ignore%20certain%20sheets%3F%20As%20I%20have%20two%20sheets%20that%20I%20am%20using%2C%20one%20for%20a%20Data%20table%2C%20for%20dropdown%20boxes%2C%20and%20the%20other%20for%20a%20Reference%20sheet%2C%20that%20has%20everything%20locked%20so%20nothing%20can%20be%20changed%20on%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20found%20multiple%20web%20results%20on%20doing%20this%2C%20but%20I%20am%20wondering%20if%20it%20is%20possible%20to%20do%20what%20I%20am%20thinking%20of%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20any%20help%20anyone%20can%20give%20on%20this.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1924385%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1924757%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20color%20Filled%20Cells%20across%20entire%20workbook%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1924757%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F873280%22%20target%3D%22_blank%22%3E%40enuff_2live%3C%2FA%3E%26nbsp%3B%2C%20if%20you%20can%20decide%20to%20assign%20only%20specific%20color%20shade%20(cell%20format)%20to%20the%20cells%20to%20be%20counted%20across%20the%20workbook%2C%20then%20one%20way%20is%20to%20simply%20use%20Ctrl%2BF%20(find)%20dialogue%20box%20%2C%20expand%20the%20options%2C%20use%20cell%20format%20as%20the%20item%20to%20be%20found%20%2C%20select%20workbook%20instead%20of%20sheet%20in%20%22within%22%20and%20click%20Find%20all%20to%20know%20the%20cell%20addresses%20and%20cell%20count.%3C%2FP%3E%3CP%3EIt%20does%20not%20address%20%22ignoring%20specific%20cells%2Fspecific%20sheets%22%20requirement%2C%20but%20perhaps%20it%20is%20a%20ready%20at%20hand%2070%25%20of%20the%20solution%20(%3F)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22amit_bhola_0-1606156566825.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F235619i95795382EC39626F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22amit_bhola_0-1606156566825.png%22%20alt%3D%22amit_bhola_0-1606156566825.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1925131%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20color%20Filled%20Cells%20across%20entire%20workbook%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1925131%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F636579%22%20target%3D%22_blank%22%3E%40amit_bhola%3C%2FA%3EThank%20you%20for%20the%20reply.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20cells%20are%20K16-K45%20on%20the%20sheets%20I%20want%20to%20count.%20The%20sheets%20can%20be%20copied%2C%20if%20we%20need%20more%20%22pages%22.%20The%20cells%20will%20be%20Highlighted%20using%20a%20Macro%20Button.%20They%20are%20going%20to%20be%20randomly%20highlighted%2C%20as%20we%20process%20the%20material.%20So%20I%20can't%20use%20the%20Find%20function.%20Also%20I%20want%20to%20record%20it%20and%20show%20it%20to%20keep%20track%20of%20finished%20parts.%20I%20would%20like%20to%20either%20make%20it%20update%20automatically%20or%20with%20a%20button.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1928090%22%20slang%3D%22en-US%22%3ERe%3A%20Counting%20color%20Filled%20Cells%20across%20entire%20workbook%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1928090%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F873280%22%20target%3D%22_blank%22%3E%40enuff_2live%3C%2FA%3E%26nbsp%3B%2C%20with%20Macro%20(VBA)%20it%20is%20possible%20to%20count.%20Attached%20sheet%20is%20an%20example%20how%20it%20can%20be%20done%20by%20VBA.%20It%20has%202%20buttons.%201st%20button%20populates%20the%20sheet%20names%20(%22pages%22)%20and%20applicable%20cells%20addresses.%20Then%20user%20can%20type%20%22Y%22%20against%20the%20sheets%20to%20be%20considered%20for%20calculation.%20Then%20the%202nd%20button%20calculates%20the%20filled%20cells%20in%20the%20applicable%20cells%20of%20the%20considered%20sheets.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThough%20the%20file%20is%20attached%2C%20and%20code%20is%20enclosed%20below%20as%20well%2C%20still%20there%20can%20be%20n%20number%20of%20user%20scenarios%20which%20need%20consideration%20in%20VBA%20programming%20%2F%20errors%20trapping%20etc.%20That%20level%20of%20build%20and%20testing%20is%20not%20possible%20to%20ensure.%20May%20pls.%20take%20it%20as%20a%20hint%20for%20further%20development%20at%20your%20end.%3C%2FP%3E%3CP%3E(You%20mentioned%20that%20you%20have%20created%20some%20Macros%2C%20so%20i%20assume%20that%20you%20can%20build%20on%2C%20catch%20the%20line%20of%20the%20code)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22amit_bhola_0-1606243710682.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F235795i79F238AA9859AE59%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22amit_bhola_0-1606243710682.png%22%20alt%3D%22amit_bhola_0-1606243710682.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20PopulateSheetNames_Click()%0A%0ADim%20InputCellAnchor%20As%20Range%0ADim%20i%20As%20Integer%0A%0ASet%20InputCellAnchor%20%3D%20Worksheets(%22Count%20Console%22).Range(%22B6%22)%0A%0AFor%20i%20%3D%201%20To%20Worksheets.Count%20-%201%0A%20%20%20%20InputCellAnchor.Offset(i%2C%200)%20%3D%20i%0A%20%20%20%20InputCellAnchor.Offset(i%2C%201)%20%3D%20Worksheets(i%20%2B%201).Name%0A%20%20%20%20InputCellAnchor.Offset(i%2C%202)%20%3D%20%22K16%3AK45%22%0ANext%0A%0AEnd%20Sub%0APrivate%20Sub%20CountColoredCells_Click()%0A%0ADim%20InputCellAnchor%20As%20Range%0ADim%20OutputCell%20As%20Range%0ADim%20sht%20As%20Worksheet%0ADim%20rngadd%20As%20String%0ADim%20i%20As%20Integer%20%20%20%20%20%20%20%20'counter%20for%20sheet%0ADim%20j%20As%20Integer%20%20%20%20%20%20%20%20'counter%20for%20filled%20cells%20in%20the%20considered%20sheet%0ADim%20k%20As%20Integer%20%20%20%20%20%20%20%20'total%20filled%20cells%20counter%0A%0ASet%20InputCellAnchor%20%3D%20Worksheets(%22Count%20Console%22).Range(%22C7%22)%0ASet%20OutputCell%20%3D%20Worksheets(%22Count%20Console%22).Range(%22J2%22)%0A%0Ai%20%3D%200%0Ak%20%3D%200%0AOutputCell.Value%20%3D%20%22%22%0A%0ADo%20While%20InputCellAnchor.Offset(i%2C%200)%20%26lt%3B%26gt%3B%20%22%22%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'till%20the%20case%20that%20sheet%20name%20is%20not%20blank%0A%20%20%20%20Set%20sht%20%3D%20Worksheets(CStr(InputCellAnchor.Offset(i%2C%200)))%0A%20%20%20%20rngadd%20%3D%20InputCellAnchor.Offset(i%2C%201)%0A%20%20%20%20If%20InputCellAnchor.Offset(i%2C%202)%20%3D%20%22Y%22%20Then%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'if%20that%20sheet%20is%20inputted%20as%20%22Y%22%20i.e.%20considered%0A%20%20%20%20%20%20%20%20j%20%3D%200%0A%20%20%20%20%20%20%20%20For%20Each%20c%20In%20sht.Range(rngadd).Cells%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'scan%20all%20applicable%20cells%20in%20that%20sheet%0A%20%20%20%20%20%20%20%20%20%20%20%20With%20c.Interior%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20Not%20.Pattern%20%3D%20xlNone%20And%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.TintAndShade%20%3D%200%20And%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.PatternTintAndShade%20%3D%200%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20j%20%3D%20j%20%2B%201%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'count%20if%20it%20is%20filled%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20Next%0A%20%20%20%20%20%20%20%20InputCellAnchor.Offset(i%2C%203)%20%3D%20j%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'output%20sheet%20level%20count%0A%20%20%20%20%20%20%20%20k%20%3D%20k%20%2B%20j%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20InputCellAnchor.Offset(i%2C%203)%20%3D%20%22%22%0A%20%20%20%20End%20If%0A%20%20%20%20i%20%3D%20i%20%2B%201%0ALoop%0A%0AOutputCell.Value%20%3D%20k%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'output%20global%20count%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
New Contributor

I am working on a project to help stream line and improve my works Material Process Sheets. I have made a few Macros and have some conditional formatting in the Workbook. 

 

The Workbook contains Locked and unlocked cells and sheets. Part of the daily process is to check in and track were the material is in the process, weather it is on order or in the machine shop, or even out for treatment. We do this by "highlighting" the cell with the fill feature. I would like to count the last cell in each row when it has been "Highlighted", meaning all processes are done at the material is ready to be assembled. The Workbook can have from one to multiple pages. So here is my question, is there a way to count the filled cells across the Workbook, but limit to a specific set of cells on each Sheet and limit to only look at certain sheets or ignore certain sheets? As I have two sheets that I am using, one for a Data table, for dropdown boxes, and the other for a Reference sheet, that has everything locked so nothing can be changed on it.

 

I have found multiple web results on doing this, but I am wondering if it is possible to do what I am thinking of?

 

Thank you for any help anyone can give on this.

5 Replies

@enuff_2live , if you can decide to assign only specific color shade (cell format) to the cells to be counted across the workbook, then one way is to simply use Ctrl+F (find) dialogue box , expand the options, use cell format as the item to be found , select workbook instead of sheet in "within" and click Find all to know the cell addresses and cell count.

It does not address "ignoring specific cells/specific sheets" requirement, but perhaps it is a ready at hand 70% of the solution (?)

 

amit_bhola_0-1606156566825.png

 

@amit_bholaThank you for the reply.

 

The cells are K16-K45 on the sheets I want to count. The sheets can be copied, if we need more "pages". The cells will be Highlighted using a Macro Button. They are going to be randomly highlighted, as we process the material. So I can't use the Find function. Also I want to record it and show it to keep track of finished parts. I would like to either make it update automatically or with a button.

Best Response confirmed by enuff_2live (New Contributor)
Solution

@enuff_2live , with Macro (VBA) it is possible to count. Attached sheet is an example how it can be done by VBA. It has 2 buttons. 1st button populates the sheet names ("pages") and applicable cells addresses. Then user can type "Y" against the sheets to be considered for calculation. Then the 2nd button calculates the filled cells in the applicable cells of the considered sheets.

 

Though the file is attached, and code is enclosed below as well, still there can be n number of user scenarios which need consideration in VBA programming / errors trapping etc. That level of build and testing is not possible to ensure. May pls. take it as a hint for further development at your end.

(You mentioned that you have created some Macros, so i assume that you can build on, catch the line of the code)

 

amit_bhola_0-1606243710682.png

 

Private Sub PopulateSheetNames_Click()

Dim InputCellAnchor As Range
Dim i As Integer

Set InputCellAnchor = Worksheets("Count Console").Range("B6")

For i = 1 To Worksheets.Count - 1
    InputCellAnchor.Offset(i, 0) = i
    InputCellAnchor.Offset(i, 1) = Worksheets(i + 1).Name
    InputCellAnchor.Offset(i, 2) = "K16:K45"
Next

End Sub
Private Sub CountColoredCells_Click()

Dim InputCellAnchor As Range
Dim OutputCell As Range
Dim sht As Worksheet
Dim rngadd As String
Dim i As Integer        'counter for sheet
Dim j As Integer        'counter for filled cells in the considered sheet
Dim k As Integer        'total filled cells counter

Set InputCellAnchor = Worksheets("Count Console").Range("C7")
Set OutputCell = Worksheets("Count Console").Range("J2")

i = 0
k = 0
OutputCell.Value = ""

Do While InputCellAnchor.Offset(i, 0) <> ""                     'till the case that sheet name is not blank
    Set sht = Worksheets(CStr(InputCellAnchor.Offset(i, 0)))
    rngadd = InputCellAnchor.Offset(i, 1)
    If InputCellAnchor.Offset(i, 2) = "Y" Then                  'if that sheet is inputted as "Y" i.e. considered
        j = 0
        For Each c In sht.Range(rngadd).Cells                   'scan all applicable cells in that sheet
            With c.Interior
                If Not .Pattern = xlNone And _
                       .TintAndShade = 0 And _
                       .PatternTintAndShade = 0 Then
                    
                   j = j + 1                                    'count if it is filled
                   
                End If
            End With
        Next
        InputCellAnchor.Offset(i, 3) = j                        'output sheet level count
        k = k + j
    Else
        InputCellAnchor.Offset(i, 3) = ""
    End If
    i = i + 1
Loop

OutputCell.Value = k                                            'output global count

End Sub

@amit_bhola Wow, that is really close to what I am looking for. I just tried it in my Workbook and was able to get it to mostly work. Will just need to see if I can get it to work under one button. Thank you for the help. This was extremely helpful.

Glad to know that it helped.
Yes, as per your actual workbook needs, it may need some adjustments at your end, e.g. in template I shared, the console sheet is assumed to be always the 1st sheet so it is not populated as a sheet name by 1st button. The 1st button is only for input convenience, not required again and again once the pages have been listed.
Console type of input method adds to flexibility for future, e.g. if the cells addresses expand to a bigger range than just K16:K45 in future, or if the cells addresses are different for different sheets, it can be easily incorporated just by typing in console sheet.