ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting blank values from an array (https://www.excelbanter.com/excel-programming/349616-deleting-blank-values-array.html)

chemdude77

Deleting blank values from an array
 
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

alan_stew

Deleting blank values from an array
 
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


chemdude77

Deleting blank values from an array
 
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

"alan_stew" wrote:

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




All times are GMT +1. The time now is 12:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com