I want to check just the Header Row for each sheet in a single workbook against a static array of Header names, My code works to find what's missing, how do I account for headers that are extra, and put a msgbox up that tells the user there's an extra column, or columns, on a given sheet?
Code:
Sub CheckHeadersAllSheets()
Dim destinationSheet As Worksheet, destRow As Long, destCol As Variant
Dim ws As Worksheet, wsRow As Long, wsCol As Variant
Dim columnHeader As Variant
Set destinationSheet = ThisWorkbook.Worksheets("Master")
For Each ws In ThisWorkbook.Worksheets
If Not ws Is destinationSheet Then
For Each columnHeader In Array("aic", "_job", "_sumry", "mpreview", "equipment", "serial", "system", "mpnbr", "mrc", "periodicty", "procedure", "tech", "notes", "Name", "Type")
With ws
wsCol = Application.Match(columnHeader, .Rows(1), 0)
If Not IsError(wsCol) Then
wsRow = .Cells(.Rows.Count, wsCol).End(xlUp).Row
destCol = Application.Match(columnHeader, destinationSheet.Rows(1), 0)
destRow = destinationSheet.Cells(destinationSheet.Rows.Count, destCol).End(xlUp).Row + 1
Else
MsgBox "Column heading " & columnHeader & " not found in row 1 of " & .Name
End If
End With
Next
End If
Next
End Sub