I did research on stack but unable to find exactly what I need or close enough to edit the code. I am pretty new to VBA.
I have bunch (> 100 files) of .csv files in a directory. The file name is consistent with this format: customer_id-inventory_id.forecast.csv.
For example: 12345678-111111.forecast.csv; 12345-222.forecast.csv; ...etc
These files have only two columns with date and forecast. I want to bring in customer_id and inventory_id from the filename into these cells for each file. Please see the original file:
12345-222.forecast.csv;
Output file after bringing in the customer_id and inventory_d. How do I write this in VBA? Thanks!
I tried: VBA - Excel Append Every Active Row With File Name
Dim LastRow As Long
Dim LastColumn As Long
Sub InsertFileName()
Application.ScreenUpdating = False
Dim i As Long
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
LastColumn = ActiveSheet.Cells(i, ActiveSheet.Columns.Count).End(xlToLeft).Column
ActiveSheet.Cells(i, LastColumn + 1) = "=CELL(""filename"")"
Next i
Application.ScreenUpdating = True
End Sub
This is not generating any file names.