Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 05:05 PM
Registered User
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I test for an empty array element

Hi!

How do I test for an empty array element?
I want to loop through an array while the array element is not empty.

Say I have an array of 3 elements:

a(1) = 1
a(2) = 2
a(3) = is empty

How can I test for a(3) being empty?

Thanks!

K Moran
 
Old October 8th, 2004, 03:34 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use the IsEmpty function, if your array contains items of a Variant type, eg.


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
In the above example, myArray(2) is returned as empty





Similar Threads
Thread Thread Starter Forum Replies Last Post
test for empty content? rakesh XSLT 2 July 29th, 2008 05:51 PM
Problem -- Empty element check ! back2grave XSLT 2 July 10th, 2006 04:58 PM
Element test Neal XSLT 3 June 13th, 2006 05:54 AM
array test 5 k_o_bliss J2EE 0 August 21st, 2005 04:32 PM
How to check if you have an empty array Ciarano VB How-To 9 March 31st, 2004 09:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.