Deleting blank values from an array

G

Guest

Hi... newbie here. I have a 2D array that has blank values that I would like
to remove. I searched and found this code:

'Where Arr is array containing blanks and Arr2 is dynamic array
ii = 0
For i = LBound(Arr) To UBound(Arr)
If Arr(i) <> "" Then
ReDim Preserve Arr2(ii)
Arr2(ii) = Arr(i)
ii = ii + 1
End If
Next

However, I am getting an error 9: subscript out-of-range for the "If Arr(i)
<> "" Then" line and I can't figure out why. The only thing I can think of is
that this code is for a 1D array? Any comments? If so, how do I change the
code to remove blanks from a 2D array. Thanks!

Matt
 
A

alan_stew

Matt,
How about putting this line in your code temporarily to see what is
going on:
MsgBox "i: " & i

I'd put it right after the "For i = blah blah....

Alan
 
G

Guest

Hi Alan,

Thanks for the help, that tip should definitely help me debug in the future.
I ended up changing the code so that a 1D array will work and now I am
getting acceptable results. My philosophy is to make the program as simple as
possible at first and then add more difficult-to-code extras later on once I
at least have a working version.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top