Phoenix Wright
Phoenix Wright

Reputation: 5

IsEmpty returns False when target is multiple cells

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.

enter image description here

Upvotes: 0

Views: 279

Answers (1)

braX
braX

Reputation: 11755

It's right in the documentation...

False is always returned if expression contains more than one variable.

IsEmpty function


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

Related Questions