+ Reply to Thread
Results 1 to 4 of 4

Comparing arrays and deleting elements

  1. #1
    Registered User
    Join Date
    10-12-2015
    Location
    Romania
    MS-Off Ver
    07
    Posts
    2

    Comparing arrays and deleting elements

    Hello! First of all I want to mention that I'm new both to VBA and this forum. So, I'm having some problems in a project I'm working at. I have a project that requires me to compare a fixed length array to a dynamic array.
    The thing is though, i want to compare each element of the first array with every element of the second array, and if i get a match do something, and delete the matched elements from the second array. Then, again, compare them, see that there are no matches, calculate the difference between the first element of the first array and the first element of the second array, and add it to all of the elements of array 1, therefore equalizing them so that they can be deleted once more. And so on... i'm gonna do an example below, because i don't know if i made any sense.

    A1=(0,50,100,150)
    A2=(0,100,150,200,250,300,350)
    after comparison, 0=0, 100=100, and 150=150 => do something, then recreate the elements:
    A1=(0,50,100,150)
    A2=(200,250,300,350)
    compare them again, there are no matches, so add 200(elem1-elem1 of each array) to the first array=>
    A1=(200,250,300,350)
    A2=(200,250,300,350)
    now that i have a match, all element can be deleted, so the second array will be emptied . Basically, the first array empties the second one step by step, by equalizing the elements.

    This is what i have so far (the testArray is being filled up after user input):

    Please Login or Register  to view this content.
    So, after finding the duplicate values, and removing those elements ONLY from the 2nd array, i should make an addition to the first array, such that i would cause 2 other duplicates, and do this over and over again, until i've removed all of the 2nd array's elements...

    Please help me.
    Thank you!

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Comparing arrays and deleting elements

    Use Filter().

  3. #3
    Registered User
    Join Date
    10-12-2015
    Location
    Romania
    MS-Off Ver
    07
    Posts
    2

    Re: Comparing arrays and deleting elements

    Could you please be more specific? As i said, i've been using vba for a couple of days now.. Thank you.
    I got something:

    arrTemp2 = Filter(testArray, i, False)

    MsgBox Join(arrTemp2, "*")
    Last edited by consumer48; 10-12-2015 at 11:17 AM.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Comparing arrays and deleting elements

    e.g.
    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. Comparing Elements in Multiple Arrays
    By gibbsa08 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2014, 06:50 AM
  2. Replies: 7
    Last Post: 10-07-2014, 10:15 AM
  3. Arrays elements is not returns the values to Calling function
    By amarendra19 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2011, 12:44 AM
  4. Reorder elements a cell using arrays, split & join
    By k8_dog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-12-2011, 01:58 PM
  5. Accessing elements within arrays
    By JP789 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-17-2009, 08:47 AM
  6. Formula for deleting elements of a cell?
    By Janine in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-27-2007, 10:29 AM
  7. [SOLVED] Elements and Arrays in Excel
    By Lighthouseman in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-01-2006, 06:10 AM

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