+ Reply to Thread
Results 1 to 13 of 13

How to read an array

  1. #1
    Registered User
    Join Date
    09-24-2014
    Location
    Denver
    MS-Off Ver
    2010
    Posts
    2

    How to read an array

    Hi,

    I see lot of posts about arrays and how fast they work so i think that the array would be best for my issue. I started to create some code but I cant figure out how to read from array. On the data sheet i have 2 columns one with St# and Q# concatenated and on the sales sheet i have a table with st# in column A and Q# in row 2 I would like to populate the table with data from Data tab.
    Please help.

    Thanks
    Z

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Pepe Le Mokko; 03-29-2020 at 04:14 AM. Reason: Title

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Array

    Hi Zibi, here's how to read those fields in the array:


    Please Login or Register  to view this content.
    Last edited by xladept; 03-27-2020 at 11:55 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA Array

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    For such few data the obvious beginner way is the fast enough Copy method and easiest to maintain :

    PHP Code: 
    Sub Demo1()
        
    ShCalc.[B2:B13].Copy Sheet2.[B3]
        
    ShCalc.[B14:B25].Copy Sheet2.[C3]
        
    ShCalc.[B26:B37].Copy Sheet2.[D3]
        
    ShCalc.[B38:B49].Copy Sheet2.[E3]
    End Sub 

    If only the source values must be allocated to the destination range another easy way to maintain :

    PHP Code: 
    Sub Demo2()
        
    Sheet2.[B3:B14] = ShCalc.[B2:B13].Value2
        Sheet2
    .[C3:C14] = ShCalc.[B14:B25].Value2
        Sheet2
    .[D3:D14] = ShCalc.[B26:B37].Value2
        Sheet2
    .[E3:E14] = ShCalc.[B38:B49].Value2
    End Sub 

    Previous demonstration can be rewritten using a single loop :

    PHP Code: 
    Sub Demo3()
      Const 
    12
        Dim C
    %, R&
            
    1
        
    For 2 To 38 Step L
            C 
    1
            Sheet2
    .Cells(3C).Resize(L) = ShCalc.Cells(R2).Resize(L).Value2
        Next
    End Sub 

    This demonstration allocates the destination range at once with an array :

    PHP Code: 
    Sub Demo4()
      Const 
    12
        Dim V
    R&, S%, T#(1 To L, 1 To 4)
            
    ShCalc.Range("B2"ShCalc.[B1].End(xlDown)).Value2
        
    For 1 To UBound(V)
            
    R Mod L
            T
    (IIf(0LS), - (0)) = V(R1)
        
    Next
            Sheet2
    .[B3:E14] = T
    End Sub 

    Last but not least, a variation of the previous demonstration :

    PHP Code: 
    Sub Demo5()
        
    Dim VR&, ST#(1 To 12, 1 To 4)
            
    ShCalc.UsedRange.Value2
        
    For 2 To UBound(V)
            
    Split(Mid(V(R1), 3), "Q")
            
    T(S(0), S(1)) = V(R2)
        
    Next
            Sheet2
    .[B3:E14] = T
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Registered User
    Join Date
    09-24-2014
    Location
    Denver
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA Array

    Thank you All so much for the examples, this is very helpful.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Array

    You're welcome Zibi - I only showed you how to address the array. Do you have another question?

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA Array

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  8. #8
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: How to read fields of an array

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    I did it for you this time

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: How to read fields of an array


    'Fields' of an array ?‼

  10. #10
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: How to read fields of an array

    @ Marc L
    I'm open to suggestions for a better title if you have a moment to drop your usual sarcasms...

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to read fields of an array


    Again, nothing to do with any sarcasm but as I never read on any VBA documentation a VBA array has 'fields'
    so now the title is more ambiguous than it was, just my opinion …

    « How to read an array » is enough …

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How to read fields of an array

    @ Pepe

    Elements sounds better than fields.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  13. #13
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: How to read an array

    Thanks Marc and Bakerman, I corrected the title.

+ 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. Array summing inventory of a specific part (array formula) EXCEL 2007
    By fdirosa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-07-2018, 12:51 PM
  2. Replies: 5
    Last Post: 02-22-2018, 01:47 AM
  3. Replies: 1
    Last Post: 01-04-2018, 01:07 PM
  4. [SOLVED] Array formulae with different sized array, e.g. array-if() or somproduct-if()?
    By hlhans in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-09-2016, 03:59 PM
  5. [SOLVED] Populate one array from another array and print new array as a range
    By Kaden265 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 07:52 AM
  6. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM

Tags for this Thread

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