3

I have 250 different excel files inside a folder (with same layout) with columns A to F. I need to add a new column on column G. The conventional approach would be opening each file and adding new column at G. Is there any simple process using Excel macro or any other tools to get this done?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Martin S
  • 428
  • 3
  • 12

2 Answers2

3

This link helped me. Following is my solution, which works:

Sub LoopThroughFolder()

Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Dim Rws As Long, Rng As Range
Set Wb = ThisWorkbook
'change the address to suite
MyDir = "C:\Users\dell\Desktop\Folder1\" 'Your Directory
MyFile = Dir(MyDir & "*.xlsx")    'Your excel file extension
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0

Do While MyFile <> ""
    Workbooks.Open (MyFile)
        Range("G1").Value = "NewColumn" 'New Column Name
        ActiveWorkbook.Save
        ActiveWorkbook.Close True
    MyFile = Dir()
Loop

End Sub
Martin S
  • 428
  • 3
  • 12
0

Yes here's the code for open all excel files in a folder: macro - open all files in a folder

In that loop you can add a new Column to that files

Community
  • 1
  • 1
Shmukko
  • 572
  • 3
  • 11