View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default To determine if selection range contains empty rows

I'm not sure why you have set your code up as a Sub where you change its
single argument as opposed to setting it up as a Function that returns a
value (a Boolean value in your case), but I went with your set up in my code
below (including using your MyMsgBox subroutine rather than VB's built in
MsgBox). I also changed the message you were passing to your MyMsgBox
subroutine as it did not match the description you gave in your questions.
Anyway, give this a try and see if you can make use of it...

Sub IsRowEmpty(EmptyRow As Boolean)
Dim R As Range
For Each R In Selection.Rows
If R.Cells.Count - R.SpecialCells(xlCellTypeBlanks).Count < 1 Then
MyMsgBox "Not all rows in selected range have only one value."
EmptyRow = True
Exit Sub
End If
Next
End Sub

--
Rick (MVP - Excel)



"Subodh" wrote in message
...
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