vba blank cells with formulas

max_max

Board Regular
Joined
Jun 29, 2013
Messages
58
Hello everyone
this function does not work if the range cells have formulas

If WorksheetFunction.CountA(Range("A3:A100")) = 0 Then

i tried with this macro
VBA Code:
Sub vba_check_empty_cells()

Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("a3:a100")

For Each myCell In myRange
    c = c + 1
    If IsEmpty(myCell) Then
        i = i + 1
    End If
Next myCell

MsgBox _
"There are total " & i & " empty cell(s) out of " & c & "."

End Sub

the range is not empty
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try using
Excel Formula:
If Len(myCell.Value) = 0 Then
with the loop code or evaluate COUNTIF(A3:A100,"") to get a simple count of the blank cells.
 
Upvote 0
How about:
VBA Code:
Sub vba_check_empty_cells()

Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range

Set myRange = Range("a3:a100")
c = myRange.Rows.Count
i = Application.WorksheetFunction.CountIf(myRange, "")

MsgBox _
"There are total " & i & " empty cell(s) out of " & c & "."

End Sub
Or this:
VBA Code:
Sub vba_check_empty_cells()

MsgBox "There are total " & Application.WorksheetFunction.CountIf(Range("a3:a100"), "") & " empty cell(s) out of " & Range("a3:a100").Rows.Count & "."

End Sub
 
Upvote 0
In the range
Range("a3:a100")
there are formulas
What you want calculate exactly for i and c character at VBA Code?
if you want count empty cells and formulas that has empty result, this codes working correctly.
 
Upvote 0
if you want calculate number of cells with formula try this line:
VBA Code:
c= Range("a3:a100").SpecialCells(xlCellTypeFormulas).Count
 
Upvote 0
hi jason, i didn't understand how to do it
What are you actually trying to do? The whole task, not just the part that you have asked here.

There are multiple ways to count blank / empty cells, what you want to do with that count after may make one method preferable to another.
 
Upvote 0
I badly explained myself.
I don't need to know how many empty cells there are in the range "a3:a100"
but if the range is empty

If WorksheetFunction.CountA(Range("A3:A100")) = 0 Then

the formula does not work if there are formulas in the range
 
Upvote 0
You have a range of 98 cells, so
Excel Formula:
If Evaluate("=COUNTIF(A3:A100,"""")") =98 Then
Should result True if all are empty.

Does that help?
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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