Loop through several excel files and compare parts of these files with Original Template

sandro

New Member
Joined
Aug 13, 2013
Messages
4
Hello,

This may sound a little bit complex, but I am looking for a Code that would Loop through all excel files in a Folder and:

- on each excel workbook perform a check of Worksheet names with the Original template (order is not important although I can easily sort it if needed)
- on each excel worksheet (on all the workbooks in the loop) perform a check of Header column names and order

= if it will find a mismatch, for example 1st worksheet in the looped files will be named A and its name should be B (as in the TEMPLATE xls),
I will get a prompt/message box = Error found in Cell A1/Object "Sheet 1" + the object will get a yellow fill.
= The same goes for the Header cells = if A1 does not equal A1 in the template (it has different value) then message box + highlight
Also, its important the Loop will continue after prompt + fill.

I am checking 30+ excel files like this manually. Each has 3 Worksheets with 30+ columns. I am able to write a code to loop through the excel files and save them for example, but I cant figure out how to solve the compare with template + fill if different part on so many objects...

I am thinking about using and modyfing this code, But any possible solution on how to automate this is welcome.

Sub Loop_Compare_Highlight()

Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual


Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With

'In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings

'Target File Extension (must include wildcard "*")
myExtension = "*.xls"

'Target Path with Ending Extention
myFile = Dir(myPath & myExtension)

'Loop through each Excel file in folder
Do While myFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=myPath & myFile)

'Save and Close Workbook
wb.Close SaveChanges:=True

'Get next file name
myFile = Dir
Loop

'Message Box when tasks are completed
MsgBox "Task Complete!"

ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top