Prabu_sanku
New Member
- Joined
- Jun 8, 2023
- Messages
- 1
- Office Version
- 2013
- Platform
- Windows
Hi I have a macro which I want to run across multiple excel files in multiple sub folders
eg: Main folder - USA
sub folders -
1. New york
2. Washington
3. California
Each of the above subfolder contains multiple excel files. I found the below code which runs on excel files in a single folder. Please help in modifying this for runnibg across sub folders
Public Sub Format_All_Workbooks()
Dim folderPath As String
Dim fileName As String
Dim wb As Workbook
folderPath = "Folder path entered here"
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
Application.ScreenUpdating = False
fileName = Dir(folderPath & "*.xls*")
Do While fileName <> ""
Set wb = Workbooks.Open(folderPath & fileName)
Clean_Tally_Data
wb.Close SaveChanges:=True
fileName = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Clean_Tally_Data()
Dim rng As Range
Set rng = Range("B1:E2000")
For Each cell In rng
If InStr(1, cell.NumberFormat, "Cr") > 0 Then
cell.Value = cell.Value * -1
Else
cell.Value = cell.Value
End If
cell.NumberFormat = "General"
Next
End Sub
eg: Main folder - USA
sub folders -
1. New york
2. Washington
3. California
Each of the above subfolder contains multiple excel files. I found the below code which runs on excel files in a single folder. Please help in modifying this for runnibg across sub folders
Public Sub Format_All_Workbooks()
Dim folderPath As String
Dim fileName As String
Dim wb As Workbook
folderPath = "Folder path entered here"
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
Application.ScreenUpdating = False
fileName = Dir(folderPath & "*.xls*")
Do While fileName <> ""
Set wb = Workbooks.Open(folderPath & fileName)
Clean_Tally_Data
wb.Close SaveChanges:=True
fileName = Dir
Loop
Application.ScreenUpdating = True
End Sub
Sub Clean_Tally_Data()
Dim rng As Range
Set rng = Range("B1:E2000")
For Each cell In rng
If InStr(1, cell.NumberFormat, "Cr") > 0 Then
cell.Value = cell.Value * -1
Else
cell.Value = cell.Value
End If
cell.NumberFormat = "General"
Next
End Sub