+ Reply to Thread
Results 1 to 8 of 8

How do you remove/delete elements (errors) from an array?

  1. #1
    Registered User
    Join Date
    11-13-2019
    Location
    San Diego
    MS-Off Ver
    Office 2016
    Posts
    12

    How do you remove/delete elements (errors) from an array?

    How do you remove/delete elements from an array? Assume I have this array of paired numbers:

    myArray(0) = (0.375, 0.687)
    myArray(1) = (1.838, 0.159)
    myArray(2) = (1.736, 0.176)
    myArray(3) = (0.963, 0.382)
    myArray(4) = (0.324, 0.723)
    myArray(5) = (0.069, #N/A)
    myArray(6) = (0.674, 0.51)
    myArray(7) = (0.979, 0.376)
    myArray(8) = (0.069, #N/A)
    myArray(9) = (0.667, 0.513)
    myArray(10) = (0.766, 0.465)...

    I need to create an array without errors because I'll eventually need to take the correlation of the log of the numbers.

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How do you remove/delete elements (errors) from an array?

    Hi
    What about
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: How do you remove/delete elements (errors) from an array?

    Quote Originally Posted by lRobert View Post
    How do you remove/delete elements from an array? Assume I have this array of paired numbers:

    myArray(0) = (0.375, 0.687)
    myArray(1) = (1.838, 0.159)
    ...
    Is myArray really a one-dimensional array? If so, I presume the paired numbers you show are enclosed in quote marks within your program, correct? If so, mohadin's solution in Message #2 should work for you... if not, you need to show us your actual declaration for MyArray and how you assigned your paired numbers to them.

  4. #4
    Registered User
    Join Date
    11-13-2019
    Location
    San Diego
    MS-Off Ver
    Office 2016
    Posts
    12

    Re: How do you remove/delete elements (errors) from an array?

    Sorry, it's not really one dimensional. It's more accurately:

    myArray(0,0) = 0.375
    myArray(0,1) = 0.687...

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: How do you remove/delete elements (errors) from an array?

    Quote Originally Posted by lRobert View Post
    Sorry, it's not really one dimensional. It's more accurately:

    myArray(0,0) = 0.375
    myArray(0,1) = 0.687...
    One more question... is your array really zero-based? It looks like you got your values from a worksheet (because of the #N/A error). If so, I would assume you created MyArray by assigning the range of cells to the MyArray variable like this (with an assumed data range of A1:B10)...

    MyArray = Range("A1:B10").Value

    If you did it that way, your array would be one-based, not zero-based. So, can you tell us exactly how you loaded the MyArray with its values?

  6. #6
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How do you remove/delete elements (errors) from an array?

    Hi
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-13-2019
    Location
    San Diego
    MS-Off Ver
    Office 2016
    Posts
    12

    Re: How do you remove/delete elements (errors) from an array?

    I had two non-adjacent single columns of data that I read into two one-dimensional arrays. I then combined them into a single two-dimensional array by looping through the one-dimensional arrays. (Likely inelegantly.)

    I would like to measure the correlation between the data from the columns. The data must remain "in pairs" and cannot include errors. Hence, my desire to delete the error elements from the two-dimensional array. I've researched collections, but am a bit baffled by the code examples given.

    I was able to suppress the error elements when I debug print, but that just skipped over them. However, that made it seem like creating a new array without the errors would be an easy task for me.

    I was also able to re-read the original one-dimensional array with the errors and create a shorter (redimensioned) one-dimensional array without the errors with Redim Preserve... I failed doing the same with the two-dimensional array. It's important that data be deleted in matched pairs (same row/index) as mentioned. That is why I am trying to modify the two-dimensional array.
    Last edited by lRobert; 11-25-2019 at 03:52 PM.

  8. #8
    Registered User
    Join Date
    11-13-2019
    Location
    San Diego
    MS-Off Ver
    Office 2016
    Posts
    12

    Re: How do you remove/delete elements (errors) from an array?

    I solved my problem by reading the data into an array in matched pairs and created two arrays: (1) without errors and (2) where at least one element is non-numerical.

    I had to reorient the data to use the ReDim Preserve to chop off the null values array # 1.
    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] Delete array elements from 1 column if they appear in another column. Both column in array
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2019, 11:59 AM
  2. find array length got using split feature and valdate array elements
    By malathi1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2018, 04:51 AM
  3. [SOLVED] Excel IsNumber Function treats array elements differently from range elements
    By Alan Beban in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-31-2018, 02:22 PM
  4. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  5. How to delete block of elements from stored VBA array string
    By nuttyengineer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2013, 07:06 PM
  6. [SOLVED] Use entire array elements to delete rows
    By Surreall in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-04-2012, 07:06 AM
  7. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 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