+ Reply to Thread
Results 1 to 20 of 20

Comparing arrays....

  1. #1
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Comparing arrays....

    I have two arrays that store information from two different workbooks.
    Please Login or Register  to view this content.
    This is how the information is stored, and it stores just fine, but what I need to do now is compare the two arrays and have a check that runs ThisMonthArray and checks each element of that array vs the entire array of LastMonthArray. I've tried do do this with for loops but I can not get it to compare correctly... Any help on this would be greatly appreciated.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing arrays....

    What is the goal of this, what are you checking for and what do you want to happen should/n't be found?

  3. #3
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    I'm comparing accounts from two different workbooks and these arrays when compared should do one of three things either the account is still active, it has been deleted, or it is a new account, sorry I forgot to include this information. The instance of the account being deleted ( its in the last month but not in this month) The instance of it being new ( its in thismontharray and not last month's array) and if its still active its in both arrays.
    Last edited by Bedlam; 11-02-2011 at 11:21 AM.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing arrays....

    Can you post a sample of your workbook after the import?

    Also depending on your GetData code, this doesn't look particularly efficient

  5. #5
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    http://img839.imageshack.us/img839/5843/blehb.png is the output of my worksheet

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing arrays....

    Your macro really doesn't help since it's just calling another Macro, this is where the inefficiency will be.

    I'm completely confused, there are only 2 columns. are you saying you need to check whether there are any account numbers in the left that are not in the right and vice versa?

    Please post a workbook, not an image

  7. #7
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    I'm sorry for the confusion, I need to take the column to the left and check if the account number is in the column to the right. If it is then the account is still an active account. If it isn't then it is a new account. If the column to the right has a account number that the column to the left doesn't have then it is a deleted account. I hope that helps...

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing arrays....

    Not really, please post a workbook.

    What do you want to happen when these have been identified?

  9. #9
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    When these have been identified I'm going to generate a report that shows which accounts have been deleted, added, or still active. I can't really post the workbook where the information is being pulled from... but i can probably post my entire macro code if you would like to see that...

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Comparing arrays....

    Just mock up a sample workbook which shows your data after it is pulled in, how you would like it displaying and your importing code.

  11. #11
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    realistically now that i think about it... I just need a function that i can input the two arrays into and it check each element vs the other array. so something to the extent of

    Please Login or Register  to view this content.
    so when its used i could just switch the two arrays in the prompt
    getArrayStuff(ThisMonthArray,LastMonthArray)
    getArrayStuff(LastMonthArray,ThisMonthArray)
    that way its checking the accounts vs each other
    I will then be able to see if the account has either been added or deleted based on its existence in thismontharray and lastmontharray

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,753

    Re: Comparing arrays....

    Can we see a sample workbook? If you're just comparing accounts in two columns, you could do that with helper columns or conditional formatting or both. You'd use COUNTIF or VLOOKUP to do the checks.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  13. #13
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    So this is pseudo what I have in mind... it doesn't seem to wanna work but here is a go...
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    i've included a picture of my workbook... the image in the link above is the current workbook that contains the macro and pulls the information from the other two workbooks, i'm not sure what you want me to show you... sorry i'm not a new programmer but to vba i am...

  15. #15
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Comparing arrays....

    Usually you can just use a Vlookup formula for such:

    =IF(ISERROR(VLOOKUP(Act#,LastMonthAct#s,1,0)),"New Account", "Old Account")

    However, if you want to compare each element in two arrays in vba then:

    Please Login or Register  to view this content.
    Keep in mind this is VERY generic since you have not posted any sample workbook or problem.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,300

    Re: Comparing arrays....

    Quote Originally Posted by Bedlam View Post
    i've included a picture of my workbook...
    FYI, a picture is of very little use to us, since it means that we have to recreate the actual workbook in order to test. As a general rule, you will get better help with an actual workbook as most of us are too busy to spend time recreating workbooks for every post we deal with.
    Anyone who confuses correlation and causation ends up dead.

  17. #17
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    and how exactly do I get vba to use an excel formula... I've only ever coded in other languages that don't go through excel... =IF(ISERROR(VLOOKUP(Act#,LastMonthAct#s,1,0)),"New Account", "Old Account") would be great to use, if i knew how to get vba to use it.

  18. #18
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    hmm let me see about making mockup workbooks

  19. #19
    Registered User
    Join Date
    11-02-2011
    Location
    South Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Comparing arrays....

    Ok here are two mockup examples there is more in the other workbooks that i'm using, but i'm only concerned with the first two rows. The comparison should only deal with the account number though. So when it parses the information from both workbooks I'm wanting to check the account numbers vs each other. It being in mockup1 and not in mockup2 would mean the account was deleted. An account being in mockup2 and not in mockup1 would mean its a new account. If they both contain the account number then its still an active account. Maybe that will help... sorry everyone The end all result would be a list of deleted accounts and a list of new accounts to be generated in a report.
    Attached Files Attached Files
    Last edited by Bedlam; 11-02-2011 at 01:10 PM.

  20. #20
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Comparing arrays....

    Can you use a formula, or does it have to be VBA? A formula is going to work much quicker.
    Last edited by davegugg; 11-02-2011 at 03:19 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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