How can I use words to apply FOR EACH loops? Suppose I have 96 separate csv files as follows and need to change the very first cell of each. The files are
c:\2010\2010_jan_apple.csv
c:\2010\2010_jan_orange.csv
c:\2010\2010_feb_apple.csv
c:\2010\2010_feb_orange.csv
...
c:\2010\2010_dec_apple.csv
c:\2010\2010_dec_orange.csv
c:\2012\2011_jan_apple.csv
c:\2012\2011_jan_orange.csv
...
c:\2016\2016_dec_apple.csv
c:\2016\2016_dec_orange.csv
So I think there would be one FOR loop and two FOR EACH loops.
year=2010,2012,2014,2016
month=jan,feb,...,dec
type=apple,orange
My silly code is
sub a()
application.displayalerts=false
for year=2010 to 2016 step 2
workbooks.open "c:\" & year & "\" & year & "_jan_apple.csv"
cells(1,1)="apple"
with activeworkbook
.saveas
.close
end with
workbooks.open "c:\" & year & "\" & year & "_jan_orange.csv"
cells(1,1)="orange"
with activeworkbook
.saveas
.close
end with
...
next year
end sub
In VBA, can I create a list such as {"jan","feb",...,"dec"} or {"apple","orange"} to employ FOR EACH iteration? Many thanks.