Hi,
I have 2 sheets, Sheet1 : Data in row 1 headers like ID,Name, Country,State,ZIP,Invoice Number
Sheet 2 : Data in Column2 like ID*,name,Country,State,zip,invoice Number
I want the alert result as : (it has to do exact match)
Misspelled Headers in Sheet2 :
ID
Name
ZIP
Invoice Number
How is this achievable? Match function gives the alert popup for all matched case too. i have taken as 2 ranges (sheet1 and sheet 2)
Dim SourceSheet_header As Worksheet 'The data to be copied is here Dim TargetSheet_header As Worksheet 'The data will be copied here Dim ColHeaders_header As Range 'Column headers on Target sheet Dim MyDataHeaders_header As Range 'Column headers on Source sheet Dim DataBlock_header As Range 'A single column of data Dim c_header As Range 'a single cell Dim Rng_header As Range 'The data will be copied here (="Place holder" for the first data cell) Dim lastrownum_header As Integer Dim lastcolnum_header As Integer Dim get_last_cellheader_check As String 'Dim check_type As String 'Change the names to match your sheetnames: Set SourceSheet_header = Sheets("Sheet1_Data") 'sheet1 Set TargetSheet_header = Sheets("Sheet2_Details") 'sheet2 With TargetSheet_header ' Set ColHeaders_header = .Range("B2:B46") ' .Range(.Cells(1, 1), .Cells(1, .Rows.Count).End(xlToLeft)) 'Or just .Range("A1:C1") ' Set Rng_header = .Cells(.Rows.Count, 1).End(xlUp).Offset(1) lastrownum_header = Sheets("Sheet2_Details").Range("B" & Rows.Count).End(xlUp).Row Set ColHeaders_header = .Range("B2:B" & lastrownum_header) End With With SourceSheet_header ' Set MyDataHeaders_header = .Range("A1:AX1") lastcolnum_header = Range("A1").End(xlToRight).Column get_last_cellheader_check = ColumnLetter(lastcolnum_header) 'MsgBox get_last_cellheader Set MyDataHeaders_header = Range("A1:" & get_last_cellheader_check & "1") End With Dim colIndex As Long 'colIndex = Application.Match(colName, Range(Cells(RowIndex, 1), Cells(RowIndex, 100)), 0) 'Makes sure all the column names are the same: 'Each header in Source sheet must have a match on Target sheet (but not necessarily in the same order + there can be more columns in Target sheet) For Each c_header In MyDataHeaders_header If Application.WorksheetFunction.CountIf(ColHeaders_header, c_header.Value) = 0 Then MsgBox "Column : " & c_header.Value & " is missing in Sheet2_Details" End If If Application.WorksheetFunction.Match(MyDataHeaders_header.Value, ColHeaders_header, 0) Then MsgBox "Column : " & MyDataHeaders_header.Value & " misspelled in Sheet2_Details" End If Next c_header



Reply With Quote
