+ Reply to Thread
Results 1 to 4 of 4

2D VBA array

  1. #1
    Forum Contributor
    Join Date
    08-04-2004
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    186

    2D VBA array

    I know my problem is better done as a simple formula but I'm trying to get my head around arrays in VBA so this is an educational process rather than an efficiency one.

    I have "First name" in Col A and "Surname" in Col b and want to have Col C as "First Name Surname"
    With just one name I do this and it works fine.
    Please Login or Register  to view this content.
    But with multiple names I do this and it doesn't work

    Please Login or Register  to view this content.
    It's almost there as it copies each name and pastes in C but rather than each name in a single list it will copy a single name down the column and loop through each name like that. I have tried For Next which didn't work so any educational help would be appreciated.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: 2D VBA array

    Hi,

    You don't want to loop through each item in the array, only each row, so you can do something like this
    Please Login or Register  to view this content.
    It would be more efficient to write the results into another array and load that into column C at the end
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    08-04-2004
    Location
    Amsterdam
    MS-Off Ver
    2016
    Posts
    186

    Re: 2D VBA array

    Thanks!
    So Ii was right with For Next but made noobie error by using Range rather than cells and learnt a new function with UBound.
    My code actually works if i use your cells line but I get an error at the end which I guess is a result of not using Ubound

  4. #4
    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
    48,992

    Re: 2D VBA array

    Late to the party but here's a variation on a theme using just the one array:

    Please Login or Register  to view this content.
    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


+ 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. [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
  2. Replies: 3
    Last Post: 04-02-2016, 08:16 PM
  3. [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
  4. [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
  5. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 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