Reputation: 5
just curious about if I selected more than 1 cell, let's say 5, then the return from isempty is false. I am wondering why? I understand I could use other method to identify the empty cells. But I simply want to understand deeper about 'isempty' function and 'target' in selectionchange event. Thanks for your help. cheers.
Upvotes: 0
Views: 279
Reputation: 11755
It's right in the documentation...
False is always returned if expression contains more than one variable.
Here is a function that should do what you are expecting it to do:
Function AreAllEmpty(Target As Range) As Boolean
Dim r As Range
For Each r In Target
If Not IsEmpty(r) Then
AreAllEmpty = False
Exit Function
End If
Next
AreAllEmpty = True
End Function
Usage:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox AreAllEmpty(Target)
End Sub
Upvotes: 1