I have been looking for a macro that could allow me to
1- read a CSV file that has a column with a series of id values, similar to this.
[Blocked Image: https://i.stack.imgur.com/WA6vu.png]
2- Get those values and, one by one, open all the CSV files in a certain folder then copy a value in a fixed cell for each one, in the same order in which those IDs were ordered in the "master" CSV.
The result would be a number n of CSV files that were previously present in a certain folder and that now have an ID value in a particular column.
enter code here
Sub AllWorkbooks() Dim MyFolder As String 'Path collected from the folder picker dialog Dim MyFile As String 'Filename obtained by DIR function Dim wbk As Workbook 'Used to loop through each workbook On Error Resume Next Application.ScreenUpdating = False 'Opens the folder picker dialog to allow user selection With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Please select a folder" .Show .AllowMultiSelect = False If .SelectedItems.Count = 0 Then 'If no folder is selected, abort MsgBox "You did not select a folder" Exit Sub End If MyFolder = .SelectedItems(1) & "\" 'Assign selected folder to MyFolder End With MyFile = Dir(MyFolder & "*.csv", vbNormal) 'DIR gets the first file of the folder 'Loop through all files in a folder until DIR cannot find anymore Do While MyFile <> "" 'Opens the file and assigns to the wbk variable for future use Set wbk = Workbooks.Open(Filename:=MyFolder & MyFile) 'Replace the line below with the statements you would want your macro to perform Sheets(1).Range("a1").Value = 20 wbk.Close savechanges:=True MyFile = Dir 'DIR gets the next file in the folder Loop Application.ScreenUpdating = True End Sub
This code above is correctly iterating all the files in a selected folder, and in this case, I tried copying to each one of those CSV files the number 20 in cell a1, and worked. Now I need to copy a list of values that are inside a master workbook one by one in each one of those CSV files while it iterates. Any clue about how I could do it?
Thanks for any suggestions or ideas.