+ Reply to Thread
Results 1 to 3 of 3

Trying to pull from 2 arrays at the same time.

  1. #1
    Registered User
    Join Date
    07-18-2013
    Location
    nj
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Trying to pull from 2 arrays at the same time.

    Good morning! I'm so stuck.
    I have a multi column array that has a file type and with the file type I have an array of ranges I want to copy from and an array I want to copy to in the other columns.

    What I would like is for each file type...
    Copy the data from one location in the first sheet to another location in a second sheet.
    I'm trying to compile data from 21 sheets in 20 different files on a regular basis.
    I can get the first array to loop through but I can't figure out how to pull from the second one without making another loop.
    I don't want to loop through the second array, I only want the destination range associated with the source range.
    Then I know I will have to do more to get through the sheets etc.

    Any help would be greatly appreciated.
    I have been fighting with this a couple days.


    Private Sub RunSummary()

    Dim str_FileLocation As String
    Dim obj_ImportWorkbook As Object

    Dim str_PrimaryData As Variant
    Dim str_PrimaryDataOutputRow As Variant

    Dim I As Long
    Dim arr_Type(2, 3) As Variant

    arr_Type(0, 0) = "FileType1"
    arr_Type(0, 1) = "G9:G10,G16:G17,G23:G35,G41:G42,G48" 'Copy From
    arr_Type(0, 2) = "B3,B6,B9,B23,B26" 'Copy to

    arr_Type(1, 0) = "FileType2"
    arr_Type(1, 1) = "G9:G10,G16:G17,G23:G35,G41:G42,G48,G52:G56" 'Copy From
    arr_Type(1, 2) = "B3,B6,B9,B23,B26,B28" 'Copy to

    str_FileLocation = "J:\Projects\Project1\TestFiles\2021\4Q\FILENAME_CCODE_4Q_2021.xlsm"


    For I = LBound(arr_Type, 1) To UBound(arr_Type, 1)

    Set obj_ImportWorkbook = Workbooks.Open(Filename:=str_FileLocation)

    str_PrimaryData = Split(arr_Type(I, 1), ",")
    str_PrimaryDataOutputRow = Split(arr_Type(I, 2), ",")

    For Each str_PrimaryData In str_PrimaryDataOutputRow
    obj_ImportWorkbook.Worksheets("SHEETNAME 2021 4Q").Range(str_PrimaryData).Copy ThisWorkbook.Worksheets("CCODE").Range(str_PrimaryDataOutputRow)
    Next
    Next I

    obj_ImportWorkbook.Close

    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Trying to pull from 2 arrays at the same time.

    Please Login or Register  to view this content.
    leave the - 1 out for the run with all.
    Please Login or Register  to view this content.
    Experience trumps academics every day of the week and twice on Sunday.

  3. #3
    Registered User
    Join Date
    07-18-2013
    Location
    nj
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Trying to pull from 2 arrays at the same time.

    Awesom thanks, I'll give it a try today and report back.

+ 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] Bulk Merge Text through Arrays to reduce processing time
    By analystbank in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-17-2024, 03:15 AM
  2. Backwards compatibility for 365 Dynamic Arrays & Run time errors
    By FrancesLD in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-17-2020, 05:17 AM
  3. Run Time Error for arrays
    By santum4 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-05-2016, 07:04 PM
  4. [SOLVED] Arrays: Run-time error '424': Object required
    By Billroz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-02-2016, 08:23 PM
  5. Using arrays with application.vlookup still taking time
    By Ranmandaman in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-22-2013, 11:43 AM
  6. Sum time with criteria of 3 arrays
    By Nazerith in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-05-2011, 09:32 PM
  7. Ok, one more thing, Pull just the Time out of a Time and Date Cell?
    By nbaj2k in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2006, 04:02 PM

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