Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 7th, 2004, 05:05 PM
Registered User
 
Join Date: Sep 2004
Location: san diego, ca, USA.
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
__________________
K Moran
Reply With Quote
  #2 (permalink)  
Old October 8th, 2004, 03:34 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:17 AM



All times are GMT -4. The time now is 12:29 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.