+ Reply to Thread
Results 1 to 5 of 5

Formula/VBA code to remove an element in Array by its position

  1. #1
    Registered User
    Join Date
    05-30-2017
    Location
    India
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Formula/VBA code to remove an element in Array by its position

    Hi,

    I was looking for a simple formula which will remove specific element by its position from an array

    for example INDEX(array,row_number) which will return the content in "row_number" of a specific array ,

    similarly i would want a user defined formula (even by existing pre-defined formula of excel is fine but it may be very complicated i hope, so either by VBA code is also fine)

    like rm.ele(array,row_number) where it should get as :

    input array :

    ar.1 = {1,2,3....65,66,67.. 100} -- total 100 elements (single dimension array)
    ar.2 = {1,1,1....1,1,1...1} -- total 100 elements (single dimension array)
    ar.3 = {a,b,c.... l,m,n....x,y,z} --total 26 elements (single dimension array)

    execution as : rm.ele(ar.1,66) ; rm.ele(ar.2,66) ; rm.ele (ar.3,25), should return

    ar.1 = {1,2,3....65,67..100} -- total 99 elements and removal of value - 66 which is the row_number as-well ;
    ar.2 = {1,1,1....1,1..100} -- total 99 elements and removal of value - 1 which is at row_number 66 ;
    ar.3 = {a,b,c...l.m.n...x,z} -- total 25 elements and removal of value - "y" which is at row_number 25;

    Please make the code works for string and numbers

    Thanks
    Venkatesh MG

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Formula/VBA code to remove an element in Array by its position

    Hi,

    See the DeleteArrayElement function here- http://www.cpearson.com/Excel/VBAArrays.htm
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    05-30-2017
    Location
    India
    MS-Off Ver
    MS Office 2016
    Posts
    11

    Re: Formula/VBA code to remove an element in Array by its position

    Hi,

    Thanks for the link.
    I tried exploring and just did a simple copy of whole code to VBA (Alt+F11) , but as described, it didn't returned "TRUE"(ie., progress completion) instead it returned "FALSE" indicating any possible error on the inputs or code.
    My only loop-hole i guess is, i'm not sure what Array type it requires, and how different is an array that is defined by VBA and array defined by Name manager. All of the Array i defined till now is from Name manager.
    If that is the bug location, then please indicate me how to convert Named range arrays to VBA arrays.

    Also, i just got one more requirement. is it possible to get use of the array update as a intermediate or temp.change during only one function calls and still the input array is golden.

    ie., Say ar.1 is {1..100}, by executing "DeleteArrayElement" i'm removing an element under one master function or loop, so i would also wanted ar.1 (temp) with removed element, and ar.1 (golden) without removed element - is there a way for this

    Thanks,
    Venkatesh MG

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Formula/VBA code to remove an element in Array by its position

    I suggest you provide a workbook with a clear explanation of exactly what you are doing and what you have tried. The simple answer to your last question is to copy the array into another variable and pass that to the function.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Formula/VBA code to remove an element in Array by its position

    Quote Originally Posted by VMG View Post

    input array :

    ar.1 = {1,2,3....65,66,67.. 100} -- total 100 elements (single dimension array)

    ar.1 = {1,2,3....65,67..100} -- total 99 elements and removal of value - 66 which is the row_number as-well ;
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Keeping track of element position in for each...loop?
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-26-2016, 02:26 PM
  2. Replies: 12
    Last Post: 01-14-2014, 01:56 PM
  3. [SOLVED] calling nth element in an array to be used in another code
    By vick2075 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-04-2013, 10:48 AM
  4. Remove array position
    By dlemos in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2010, 06:15 PM
  5. Extract a single element from an array formula
    By JDavies in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-04-2009, 09:10 PM
  6. Replies: 4
    Last Post: 05-09-2009, 04:45 AM
  7. Replies: 1
    Last Post: 08-03-2007, 05:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1