I want to open a file (not all the files in a folder), add a column, save the change, and then close. I want to iterate through some files and do the same things.
I saved my file with names including date (yyyymmdd) such as output_20181112_samples.csv
Let's say I want to iterate through two files, output_20181113_samples.csv & output_20181114_samples.csv
I thought I could use I (iteration index) and put it in the middle of the file name but it didn't work out. I tried to find a solution but most of the answers are for iterating through all the files in a folder.
Sub open_add_col_save_close()
Dim i As Interger
For i = 1 To 10
Select Case i
Case 3, 4
Workbooks.Open Filename:="C:\Users\todd\Downloads\output_2018111" & i & "_samples.csv"
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "2018111" & i
ActiveCell.Offset(0, 0).Select
Selection.Copy
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.End(xlUp).Select
ActiveCell.FormulaR1C1 = "date"
Range("B2").Select
Workbooks("output_2018111" & i & "_samples.csv").Save
SendKeys "%s~"
Workbooks("output_2018111" & i & "_samples.csv").Close
End Select
Next i
End Sub