+ Reply to Thread
Results 1 to 4 of 4

Excel 2007 VBA - filling an array element with results from a vlookup

  1. #1
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Excel 2007 VBA - filling an array element with results from a vlookup

    Hi all,

    I'm working with arrays (as a learning tool so far they're awesome) but i'm having a couple of problems which I'm struggling to solve.

    assuming my array is defined as Arr = (N, 34) where N is a fluctuating number of rows how would I populate (N, 34 ) with the results of the vlookup where my lookup reference is (N, 2) and my lookup array is a range("A:B") on a worksheet("Sheet1").

    I tried:
    Please Login or Register  to view this content.
    But this through up a runtime error 1004 unable to get the VLookup property of the worksheetfunction class?

    my second issue which i think isn't possible but I thought I'd ask anyhow is is it possible to perform "COUNTIFS" within the array (and potentially write this result to an element within a second array) rather than what i'm doing at the moment which is the array back to a worksheet and doing the calculation there rather than within the array.
    Last edited by Kramxel; 08-05-2015 at 04:14 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,620

    Re: Excel 2007 VBA - filling an array element with results from a vlookup

    Are you sure that value stored in Arr(N,2) is present in column A Sheet1?
    Probably this is the cause.
    Just to make sure, I tested the short code:

    Please Login or Register  to view this content.
    and if there is 100 in column A code works perfect, while it there is no such value - error 1004 occurs.
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,620

    Re: Excel 2007 VBA - filling an array element with results from a vlookup

    PS. if that's the case think of some error handling. Simplest one could be for instance:
    Please Login or Register  to view this content.
    As far as I know, you cant use COUNTIFS for an array. So either you can do what you did before (pasting array temporarily to the worksheet) or just use a loop to go through array rows counting these wher conditions you would use in COUNTIFS are fulfilled)

  4. #4
    Forum Contributor
    Join Date
    09-05-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003 Excel 2007
    Posts
    383

    Re: Excel 2007 VBA - filling an array element with results from a vlookup

    Hi Kaper,

    You're spot on my look up reference in some instances isn't in the range A:B (this is actually intentional, the Range A:B is created by the values in the data that feeds (N, 2) but I have then got rid of entries i didn't want to look at, forgetting that the'd still at this point be in the data going into the array.

    just deciding if I should be ignoring the error and moving on or if i should remove these entries from the raw data before loading it into the array.
    Last edited by Kramxel; 08-05-2015 at 09:34 AM. Reason: EDIT - I TOTALLY LIED!

+ 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. Replies: 12
    Last Post: 01-14-2014, 01:56 PM
  2. Taking an element in array (variant type) in Excel VBA
    By blackarrow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2013, 01:45 PM
  3. [SOLVED] Read last element of Split array and then discard it and resize the array.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 06:36 PM
  4. macro to sum all element in array and output it in one cell of excel.
    By mithil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2010, 04:28 PM
  5. [SOLVED] Excel 2007 : Vlookup-Need Multiple Results
    By BiduraKumar in forum Excel General
    Replies: 7
    Last Post: 08-31-2010, 02:39 AM
  6. Replies: 3
    Last Post: 03-31-2010, 11:47 AM
  7. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  8. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 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