+ Reply to Thread
Results 1 to 3 of 3

VBA loop using two arrays

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    VBA loop using two arrays

    Hi

    This is probably a very easy question to solve but i need to create a loop which loops through two arrays. The loop should first loop through an array of path name variables to open the files (and if the files arn't there more to the next one)

    Then it should copy data from the file opened and paste it into another workbook using a second array for the sheet name.

    I am sorry if i have not explained that very well.

    I have created the following loop, however i get a type mismatch
    error

    Please Login or Register  to view this content.
    Does anyone know how to do this as i am not sure??

    Thank you

    Jeskit

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VBA loop using two arrays

    hi, jeskit, you nearly have everything done but there are some things to correct:
    1. If Option base 1 is absent before Sub line your PathArray will start from zero not one, so it should be:
    Please Login or Register  to view this content.
    Same goes for SheetArray.
    2. The workbook with each path will be opened once so this "workbook-opening" line should be in first loop:
    Please Login or Register  to view this content.
    3. To access value in for example PathArray here you need to use this:
    Please Login or Register  to view this content.
    So PathArray(X) when X=0 gives you value "Path1"
    Same goes for SheetArray.

  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: VBA loop using two arrays

    Hi

    Thanks for replying!

    I have made th changes you suggested but it stills produces a type mismatch error on the line For Y = 1.

    Please Login or Register  to view this content.
    p.s. Option Base 1 is now not absent from above the sub-line

+ 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