+ Reply to Thread
Results 1 to 4 of 4

Determining whether an array contains a value

  1. #1
    Registered User
    Join Date
    06-23-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2010/2007
    Posts
    34

    Determining whether an array contains a value

    Hi guys, let's say i have an array called name(5)

    What if i didn't initialize the entries of this array, how am I gonna check if, say, name(1) is defined?

    Thanks!

  2. #2
    Registered User
    Join Date
    04-16-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Determining whether an array contains a value

    Hi,

    You could check with the following code:

    Public Sub testForEmpty()
    Dim myArray(3)
    Dim item
    Dim counter As Long

    myArray(0) = "string value"
    myArray(1) = 1.5
    myArray(3) = False

    For Each item In myArray
    If IsEmpty(item) Then
    Debug.Print "Item " & counter & " in the array is empty"
    End If
    counter = counter + 1
    Next
    End Sub
    Let me know if you need any further assistance.

  3. #3
    Registered User
    Join Date
    06-23-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2010/2007
    Posts
    34

    Re: Determining whether an array contains a value

    Quote Originally Posted by nnram123 View Post
    Hi,

    You could check with the following code:



    Let me know if you need any further assistance.

    Hi nnram123, i was just wondering, how do you check if myArray(2), and myArray(2) alone is empty? thanks!

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Determining whether an array contains a value

    Whether they are Empty or not will partly depend on how the Array was defined.

    If non-variant it won't be empty... if Variant then

    Please Login or Register  to view this content.
    @nnram123 - please use CODE tags rather than QUOTE tags for your VBA
    @secondrate - please do not quote entire posts in your reply - clutters the board (and your thread)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1