ragav_in
Board Regular
- Joined
- Feb 13, 2006
- Messages
- 89
- Office Version
- 365
- 2016
- Platform
- Windows
Dear Friends and Forum users,
I am currently working on a activity that needs to be open multiple files within a folder and, check the Column order (Columns A to Column D) in first worksheet of each workbook against a pre-defined Column order (Column A to Column D) in a workbook called Template (and this is where the Macro is written and to be executed). I did some research on this and got this code which currently compares 2 worksheets in a particular workbook for the Column order and generates a Msgbox if the order does not match.
Source: Check order of columns
Macro to compare Column Order
I would want to know how to use this code to perform my activity of looping through multiple files in folder and perform this checking of order of columns. If it finds workbook that does not match the column order as mentioned in the Template, then, it should write that workbook name to a cell in another worksheet, so that at end of the macro execution, the column will have the list of workbooks from that folder that do not match the Columns order as mentioned in the Template worksheet.
I know this is a big ask, but I feel that this forum would provide me support in getting the resolution for the same. I thank everyone who puts their time and effort to go through this post and provide any suggestions that could help in accomplishing the task.
Many thanks in advance for all your support till date.
Thanks and grateful,
ragav_in
I am currently working on a activity that needs to be open multiple files within a folder and, check the Column order (Columns A to Column D) in first worksheet of each workbook against a pre-defined Column order (Column A to Column D) in a workbook called Template (and this is where the Macro is written and to be executed). I did some research on this and got this code which currently compares 2 worksheets in a particular workbook for the Column order and generates a Msgbox if the order does not match.
Source: Check order of columns
Macro to compare Column Order
VBA Code:
Sub CompareFields()
Dim templateColumns(), sourceColumns(), col As Integer
templateColumns = Worksheets(1).Range("A1:D1").Value
sourceColumns = Worksheets(2).Range("A1:D1").Value
For col = 1 To UBound(templateColumns, 2)
If templateColumns(1, col) <> sourceColumns(1, col) Then
MsgBox "Source data not in the correct order"
Exit For
End If
Next col
End Sub
I would want to know how to use this code to perform my activity of looping through multiple files in folder and perform this checking of order of columns. If it finds workbook that does not match the column order as mentioned in the Template, then, it should write that workbook name to a cell in another worksheet, so that at end of the macro execution, the column will have the list of workbooks from that folder that do not match the Columns order as mentioned in the Template worksheet.
I know this is a big ask, but I feel that this forum would provide me support in getting the resolution for the same. I thank everyone who puts their time and effort to go through this post and provide any suggestions that could help in accomplishing the task.
Many thanks in advance for all your support till date.
Thanks and grateful,
ragav_in