+ Reply to Thread
Results 1 to 10 of 10

Read Excel named range to Array

  1. #1
    Registered User
    Join Date
    08-30-2011
    Location
    Sherbrooke, Qc
    MS-Off Ver
    Excel 2003
    Posts
    5

    Read Excel named range to Array

    This one is probably easy for you guys
    I have a named array of cell in Excel
    Ex. cells A1 to A10 are called "Description"
    I am trying to read this range into an array in VBA

    This way, if one line is added to Description, the code would read the new entry.

    Can anyone help ?
    thanks
    Last edited by dizabled; 09-01-2011 at 07:49 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Read Excel named range to Array

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Read Excel named range to Array

    Hi dizabled and welcome to the forum.

    This sounds like a job for Dynamic Named Ranges. If you add a line to your array the DYNAMIC range gets bigger.

    See http://www.ozgrid.com/Excel/DynamicRanges.htm or
    http://www.exceluser.com/explore/dynname1.htm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Read Excel named range to Array

    Hi,

    Why did you use Transpose when
    Please Login or Register  to view this content.
    seems to work also?

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Read Excel named range to Array

    That's the only way I know to reduce from a 2D to 1D vector/array

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Read Excel named range to Array

    I tried the Transpose in your code on a 4x2 array and it became a 2x4 array. Still a 2 dimensional array.

    I'm not good with getting stuff into arrays so I was excited to see your code and mine below it really put cells into a VBA array. Thanks for the lesson. Now this 2d to 1d confused me.

  7. #7
    Registered User
    Join Date
    08-30-2011
    Location
    Sherbrooke, Qc
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Read Excel named range to Array

    Thanks for helping me out.

    What's with "application", what does this refer to ?
    I was trying to work around using
    workbook(Mybook).sheet(Mysheet).range(myrangename)

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Read Excel named range to Array

    Hi dizabled, please use code tags around code as per rule number 3 of the forum rules (located in my signature.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: Read Excel named range to Array

    Hi,
    Application as the start means in the program you are using. Look at Application Object in
    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    Here is a hint. When in the immediate window and I want to see what words are understood, start with the word "Application" and then a period. A list of all possible next words will appear. This really helps me see what can be put after the period in objects.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,996

    Re: Read Excel named range to Array

    Some, though not all, Excel worksheet functions can be accessed by VBA by means of statements such as:
    y=Appliction.Transpose(...
    which is the same as:
    z=WorksheetFunction.Transpose(....

+ 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