+ Reply to Thread
Results 1 to 4 of 4

Read Range To Array, Then Pass Array To Function

  1. #1
    Registered User
    Join Date
    09-17-2010
    Location
    UT, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Read Range To Array, Then Pass Array To Function

    Dear All,

    I'm trying to write some code to do a fancy series of searches, but before I can do that, I need to create a list of unique elements (ie get rid of duplicates). I used an example I found somewhere to write my own function that does the job, and works fine for arrays defined item by item in excel vba.

    Please Login or Register  to view this content.
    This works fine on arrays that are defined via excel vba enumerating each element. However, if I try to pass an array I created by reading in from a range of values it gives me a "subscript out of range" error. If I try to redim the range it also gets angry, although for different reasons. What is the right way to do this? My attempt is below.

    Please Login or Register  to view this content.
    The data of interest is just a bunch of numbers (that I treat as strings really) that are all 9 digits long. Thanks much for your help.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Read Range To Array, Then Pass Array To Function

    You can generate unique listings in a number of ways (Collections, Dictionary Objects, iterating Arrays etc)

    I would suggest having a look at Colo's code: http://puremis.net/excel/code/021.shtml

    Be aware also of Array dimensions - a Range will always default to a 2d Array (with Base 1)
    (for vectors you can use Transpose to convert to 1d Array - once for vertical, twice for horizontal)
    Last edited by DonkeyOte; 09-18-2010 at 04:41 AM. Reason: missing comma in narrative

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Read Range To Array, Then Pass Array To Function

    Please Login or Register  to view this content.
    applied to a range:

    Please Login or Register  to view this content.
    Last edited by snb; 09-18-2010 at 06:22 AM.



  4. #4
    Registered User
    Join Date
    09-17-2010
    Location
    UT, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Read Range To Array, Then Pass Array To Function

    Thanks all. It turns out DonkeyOte was right, it was a problem with dimensions. I used transpose to make it a 1D array, made sure the indicies were alright and I was good to go. It works just like I want it to now.

+ 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