View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default To determine if selection range contains empty rows

One more...

Option Explicit
Sub testme()
Dim ok As Boolean

Call IsRowEmpty(ok)

If ok = True Then
MsgBox "Selected Range Contains empty Row." _
& vbNewLine & " No Range in the selection should be empty."
Else
MsgBox "Ok to continue"
End If

End Sub
Sub IsRowEmpty(EmptyRow As Boolean)

Dim myArea As Range
Dim myRow As Range
'to check if the selected row is empty or not
EmptyRow = False

For Each myArea In Selection.Areas
For Each myRow In myArea.Rows
If Application.CountA(myRow) = 0 Then
EmptyRow = True
Exit For
End If
Next myRow
Next myArea

End Sub

=counta() will count cells that are non-empty.

This includes cells that contain formulas that evaluate to "" (or were once ""
and were converted to values, but not cleared!).

I would add some other checks to make sure the range is exactly what you want
(20 rows by 10 columns).


Subodh wrote:

I have selected a range with 20 rows and 10 columns.
I want to ensure that every rows in the selectin has
one value in it. Also, it should be ensured that every row has
just one value. ie. no two columns in the same row have data in
it. I tried the following code. I need the suggestions in it.
Thanks in advance.

Sub isrowempty(emptyrow As Boolean)
'to check if the selected row is empty or not
emptyrow = False
For i = 1 To Selection.Rows.Count
If IsEmpty(Selection.Range("A" & i)) Then
If IsEmpty(Selection.Range("B" & i)) Then
If IsEmpty(Selection.Range("C" & i)) Then
Mymsgbox "Selected Range Contains empty Row." _
& vbNewLine & " No Range in the selection
should be empty."
emptyrow = True
Exit Sub
End If
End If
End If

Next
End Sub


--

Dave Peterson