Hello; I currently have a spreadsheet that contains 84 column headers (A1:CF1). What I want to do is ensure the source file has not been altered (columns added, deleted, moved) before I start scraping and wrangling data.
My current approach I know is a very long way around the problem where I'd end up typing 84 separate If statements making sure each column header is named accordingly (TransactionNo, FileNo, Importer ...etc) then based on the outcome, I'd concatenate all the results into a MsgBox with LineFeed separating each. I currently started this for my test code of 4 columns and it works. Example:
If Range("A1") <> "TransactionNo" Then
A = "Column A: """ & Range("A1") & """ does not match: ""TransactionNo"""
HeaderError = True
Else
A = "Column A: OK"
End If
(repeat 84 times for each column and concatenate all into a msgbox)
Given the scope of the project (I have to do this over 4 other files about the same size) that is a lot of If Statements. I was thinking a better approach is to have a verification file that contains a single row of the Header Names, and then compare that against the Source File Header Names and return a msgbox that indicates what Columns do not match. Can I somehow Read Source1 FirstCell, Read Source2 FirstCell, make sure they match, then Read Source1 SecondCell, Read Source2 SecondCell, etc. 84 times?
Any suggestions on how I can achieve my goal?
Thank-you. Mark
My current approach I know is a very long way around the problem where I'd end up typing 84 separate If statements making sure each column header is named accordingly (TransactionNo, FileNo, Importer ...etc) then based on the outcome, I'd concatenate all the results into a MsgBox with LineFeed separating each. I currently started this for my test code of 4 columns and it works. Example:
If Range("A1") <> "TransactionNo" Then
A = "Column A: """ & Range("A1") & """ does not match: ""TransactionNo"""
HeaderError = True
Else
A = "Column A: OK"
End If
(repeat 84 times for each column and concatenate all into a msgbox)
Given the scope of the project (I have to do this over 4 other files about the same size) that is a lot of If Statements. I was thinking a better approach is to have a verification file that contains a single row of the Header Names, and then compare that against the Source File Header Names and return a msgbox that indicates what Columns do not match. Can I somehow Read Source1 FirstCell, Read Source2 FirstCell, make sure they match, then Read Source1 SecondCell, Read Source2 SecondCell, etc. 84 times?
Any suggestions on how I can achieve my goal?
Thank-you. Mark