VBA loop using two arrays

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
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 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.

Does anyone know how to do this as i am not sure??

Thank you

Jessicaseymour
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I had a go at creating the loop, however i get a type mismatch error:

Code:
'Define Path Array
PathArray = Array("Path1", "Path2", "Path3", "Path4", "Path5", "Path6", "Path7", "Path8")
SheetArray = Array("BGBL", "HUBK", "HUK", "BMW", "HBE", "HNL", "IMG", "MAN")
'Loop though path files and copy data
For X = 1 To UBound(PathArray)
    For Y = 1 To UBound(SheetArray)
        Set CCTLWB = Application.Workbooks.Open(X & "\" & "*TrackerLog*" & ".xlxs")
        Set CCTLWBCSht = CCTLWB.Sheets("Commentary")
        Set CCTLWBCLSht = CCTLWB.Sheets("CallLog")
        L = WorksheetFunction.CountA(CCTLWBCSht.Range("A:A"))
        CCTLWBCSht.Range("A" & L & "N" & L).Copy Destination:=PPCWB.Sheets(Y).Range("A1")
        
        'CCTLWBCSht.Range("A" & L & "N" & L).Copy Destination:=PPCWB.Sheets(Y).Range("A4")
            
    Next Y
Next X
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top