Loops with multiple lists
I have created a piece of code which loops througha folder and opens all the files and copies and pastes data fom a range into a certain location. However i need to change it so when it loops the file it checks the names of the file and if has certain text in paste it into different sheets.
I need it to do the following:
If it is "Graphing_MTH_Actual_Curr_Year" & "*.csv" paste data on the MTH Sheet
If it is "Graphing_MTH_Actual_Prev_Year" & "*.csv" paste data on the MTHPrevious Sheet
If it is "Graphing_YTD_Actual_Curr_Year" & "*.csv" paste data on the YTD Sheet
If it is "Graphing_YTD_Actual_Prev_Year" & "*.csv" paste data on the YTDPrevious Sheet
If it is "Graphing_R12_Actual_Curr_Year" & "*.csv" paste data on the R12 Sheet
If it is "Graphing_R12_Actual_Prev_Year" & "*.csv" paste data on the R12Previous Sheet
I have tried doing it with multiple if statements but it just crashes. I would try variables but i am unsure of how to use the.
Does anyone know how to change this loop so it checks the file name on the list above and pastes onto the correct sheet?
strFldr = "C:\Documents and Settings\SeymourJ\My Documents\Tasks\"
strFile = Dir(strFldr & "Graphing_MTH_Actual_Curr_Year" & "*.csv")
Application.Calculation = xlCalculationManual
lNextrow = 2
If Len(strFile) > 0 Then
Set wbCsv = Workbooks.Open(Filename:=strFldr & "\" & strFile)
Set wsMyCsvSheet = wbCsv.Sheets(1)
Workbooks("Book1Template.xlsx").Sheets("MTH").Cell s(lNextrow, 2).PasteSpecial
lNextrow = lNextrow + 14
'go to next file
strFile = Dir
Application.StatusBar = strFile
Loop Until Len(strFile) = 0
End IfThanks to anyone who can help.
Last edited by jeskit; April 1st, 2011 at 06:40 AM..