I am writing a VBA code in which I am trying to find if my range has empty values. The code I am writing is giving me True value even in case of empty ranges. I am adding the screen shots of data and code
Range("A1").Select
Dim last_row As Long
Dim LastCol As Integer
total_rows = Cells(Rows.Count, 1).End(xlUp).Row
net_rows = total_rows - 1
LastCol = ActiveSheet.UsedRange.Columns.Count
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Starting Year"
For each_row = 1 To net_rows Step 1
If WorksheetFunction.CountA(Range(Cells(each_row + 1, 2), Cells(each_row + 1, LastCol)).Select) = 0 Then
MsgBox "True"
Else
MsgBox "False"
End If
Next
End Sub
In above case it should True in two cases and False in rest of cases. But it is giving False in all cases. Range is is between column B and H. If could tell my error, it would be highly helpful