Counta function

fluxcapacitr609

New Member
Joined
Feb 21, 2018
Messages
24
Im trying to count the empty cells, but its counting empty cells that are colored. Any way to not count empty cells that have a color to them.

Code:
Sub percentPage()


Dim bcheck As Boolean
Dim myCell




On Error Resume Next


'January


bcheck = Evaluate("isref(Jan_2018!A1)")
If bcheck Then
    Sheets("Percentages").Range("B2").Formula = "=COUNTA(Jan_2018!A2:A500)"
    Sheets("Percentages").Range("C2").Formula = "=COUNTA(Jan_2018!B2:B500)"
End If






End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,

I think you'll have to loop through each cell in your range...

Code:
Sub Macro1()
    Dim i, j As Integer
    i = 0
    j = 0
    
    Dim ws As Worksheet
    Set ws = Worksheets("Percentages")
    
    For Each cel In Range("A2:A500")
    
        If cel.Interior.ColorIndex = xlNone And IsEmpty(cel) Then i = i + 1
        
    Next cel
    
    ws.Range("B2").Value = i
    
    For Each cel In Range("B2:B500")
    
        If cel.Interior.ColorIndex = xlNone And IsEmpty(cel) Then j = j + 1
        
    Next cel
    
    ws.Range("C2").Value = j
End Sub
 
Last edited:
Upvote 0
Ah yes my bad.
COUNTA isn't supposed to count cells if they juste have a color and Nothing in them...

Just add "= False" after IsEmpty(cel) like this :

Code:
Sub Macro1()
    Dim i, j As Integer
    i = 0
    j = 0
    
    Dim ws As Worksheet
    Set ws = Worksheets("Percentages")
    
    For Each cel In Range("A2:A500")
    
        If cel.Interior.ColorIndex = xlNone And IsEmpty(cel) = False Then i = i + 1
        
    Next cel
    
    ws.Range("B2").Value = i
    
    For Each cel In Range("B2:B500")
    
        If cel.Interior.ColorIndex = xlNone And IsEmpty(cel) = False Then j = j + 1
        
    Next cel
    
    ws.Range("C2").Value = j
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,791
Messages
6,174,603
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top