arrays

H

Hemant_india

i want to delete certain array elements
e.g.
dim arr(100)
deleted arr(87)
redim preserve arr(100-n) ' n= number of elements i deletd
any ideas?
 
B

Bob Phillips

I think you would have to move the non-sparse elements to a new array, and
then move them back. Nothing built-in AFAIK.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
A

Alan Beban

Hemant_india said:
i want to delete certain array elements
e.g.
dim arr(100)
deleted arr(87)
redim preserve arr(100-n) ' n= number of elements i deletd
any ideas?
If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook,

To remove elements 45, 68 and 87, and resize

n1 = 45
n2 = 68
n3 = 87

arr2 = MakeArray(SubArray(arr, 1, n1 - 1), SubArray(arr, n1 + 1, _
n2 - 1), SubArray(arr, n2 + 1, n3 - 1), SubArray(arr, n3 + 1, 100), 1)

Or, it it helps you to visualize more readily what's happening
Sarr1 = SubArray(arr, 1, n1 - 1)
Sarr2 = SubArray(arr, n1 + 1, n2 - 1)
Sarr3 = SubArray(arr, n2 + 1, n3 - 1)
Sarr4 = SubArray(arr, n3 + 1, UBound(arr))
arr2 = MakeArray(Sarr1, Sarr2, Sarr3, Sarr4, 1)

Alan Beban
 
A

Alan Beban

Sorry; I used Dim arr(1 to 100)

For a 0-based array you need to generalize Sarr1 to
Sarr1 = SubArray(arr, lbound(arr), n1 - 1) and change the last parameter
of the MakeArray call:

arr2 = MakeArray(Sarr1, Sarr2, Sarr3, Sarr4, 0)

And the introduction should more accurately be "To remove elements
arr(45), arr(68) and arr(87) . . ."

Alan Beban
 
H

Hemant_india

hi alan
sorry replying so late
my PC was down
i have downloaded the code
thanks
 

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