L
Legacy 93538
Guest
Hi
I am in need of help as i have no diea how to solve a problem
I ahve a macro which loops though all the files in three folders without problem but i have been told i need to change it so it loops though a list in the range "B1:H2000" and also include error handling so that if a file is not on the list it will skip it and go to the next filename.
Thsi is my loop so far:
I have been told it can be done by changing the line highligthed in red so that instead of using dir it uses a celll range but i dont know how to do this without loosing the loop as i need it to loop through the three folders as well.
Can anyone help me please!!
I am in need of help as i have no diea how to solve a problem
I ahve a macro which loops though all the files in three folders without problem but i have been told i need to change it so it loops though a list in the range "B1:H2000" and also include error handling so that if a file is not on the list it will skip it and go to the next filename.
Thsi is my loop so far:
Rich (BB code):
varFolder = Array(strFldr, strFldr2, strFldr3)
For lngMyCount = 1 To 3
ChDir varFolder(lngMyCount)
strF = Dir("Graphing_*_Actual_*_Year*.csv")
Do While strF <> ""
Set wbResults = Workbooks.Open(varFolder(lngMyCount) & "\" & strF)
wbResults.Sheets(1).Range("A2:FF15").Copy
If wbResults.Name Like strFile Then
wbNew.Sheets("MTH").Cells(Nrow, 2).PasteSpecial
Nrow = Nrow + 14
ElseIf wbResults.Name Like strFile1 Then
wbNew.Sheets("MTHPrevious").Cells(Nrow1, 2).PasteSpecial
Nrow1 = Nrow1 + 14
ElseIf wbResults.Name Like strFile2 Then
wbNew.Sheets("YTD").Cells(Nrow2, 2).PasteSpecial
Nrow2 = Nrow2 + 14
ElseIf wbResults.Name Like strFile3 Then
wbNew.Sheets("YTDPrevious").Cells(Nrow3, 2).PasteSpecial
Nrow3 = Nrow3 + 14
ElseIf wbResults.Name Like strFile4 Then
wbNew.Sheets("R12").Cells(Nrow4, 2).PasteSpecial
Nrow4 = Nrow4 + 14
ElseIf wbResults.Name Like strFile5 Then
wbNew.Sheets("R12Previous").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile6 Then
wbNew.Sheets("MTH").Cells(Nrow, 2).PasteSpecial
Nrow = Nrow + 14
ElseIf wbResults.Name Like strFile7 Then
wbNew.Sheets("MTHPrevious").Cells(Nrow1, 2).PasteSpecial
Nrow1 = Nrow1 + 14
ElseIf wbResults.Name Like strFile8 Then
wbNew.Sheets("MTH").Cells(Nrow2, 2).PasteSpecial
Nrow2 = Nrow2 + 14
ElseIf wbResults.Name Like strFile9 Then
wbNew.Sheets("MTHPrevious").Cells(Nrow3, 2).PasteSpecial
Nrow3 = Nrow3 + 14
ElseIf wbResults.Name Like strFile10 Then
wbNew.Sheets("YTD").Cells(Nrow4, 2).PasteSpecial
Nrow4 = Nrow4 + 14
ElseIf wbResults.Name Like strFile11 Then
wbNew.Sheets("YTDPrevious").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile12 Then
wbNew.Sheets("YTD").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile13 Then
wbNew.Sheets("YTDPrevious").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile14 Then
wbNew.Sheets("R12").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile15 Then
wbNew.Sheets("R12Previous").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile16 Then
wbNew.Sheets("R12").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
ElseIf wbResults.Name Like strFile17 Then
wbNew.Sheets("R12Previous").Cells(Nrow5, 2).PasteSpecial
Nrow5 = Nrow5 + 14
End If
wbResults.Close SaveChanges:=False
Application.StatusBar = strF
strF = wbGCT.Sheets("Graphing").Range("A3:A181")
Loop
Next lngMyCount
I have been told it can be done by changing the line highligthed in red so that instead of using dir it uses a celll range but i dont know how to do this without loosing the loop as i need it to loop through the three folders as well.
Can anyone help me please!!